开发者

org.hibernate.PropertyAccessException - How to get a null value out of database?

开发者 https://www.devze.com 2023-02-04 14:17 出处:网络
Here is the exception: org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of com.FOO.hibernate.Tccl.MIN.

Here is the exception:

org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of com.FOO.hibernate.Tccl.MIN.

I found that this exception happen when i try to get the null value from MIN column. There're some solutions for this issue:

  • Set "NULL" (a string) for MIN column
  • Set default value, like 0 or 0.0.

But MIN column has the INT type and 0 or 0.0 is such a value in my case.

Here is my code:

        String HQL_QUERY = "from Tccl tccl";
        Query query = session.createQuery(HQL_QUERY);
        List<Tccl> 开发者_JS百科list = query.list();
        for(Tccl tccl : list){
               //fetch data here
        }

The exception happen at:

 List<Tccl> list = query.list();

Are there any solutions for this?


You should use the Object type Integer for your field "MIN" of the Tccl class instead of the primitive type int. This will allow null values.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号