PersistenceException when I used Ebean in the Play framework

I am writing a Java web application using Play Framework 2.1.0. And I use Ebean to manage the database. But I had one problem:

I have a model class called book with an int type column called a page:

public int page; @Column(name="page") public int getPage() { return page; } public void setPage(int page) { this.page = page; } 

And the page column in my MySql database is also an int type. When I get the result (row) using Ebean, and the value of the page column in my database has the specified value, like 12, it works fine. But if the value of the page attribute is null in my database, the application throws an exception:

 Execution exception[[PersistenceException: Error loading on models.Book.page]] 

I can not handle this problem.

+4
source share
1 answer

Use the Integer wrapper, which can be null rather than int primitive:

 public Integer page; @Column(name="page") public Integer getPage() { return page; } public void setPage(Integer page) { this.page = page; } 

Then you can get \ set nulls

+6
source

Source: https://habr.com/ru/post/1498620/


All Articles