简体   繁体   English

org.hibernate.PropertyAccessException-如何从数据库中获取空值?

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

Here is the exception: 这是例外:

org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of com.FOO.hibernate.Tccl.MIN. org.hibernate.PropertyAccessException:空值已分配给com.FOO.hibernate.Tccl.MIN的原始类型设置器的属性。

I found that this exception happen when i try to get the null value from MIN column. 我发现当我尝试从MIN列获取null值时会发生此异常。 There're some solutions for this issue: 有一些解决此问题的方法:

  • Set "NULL" (a string) for MIN column 为MIN列设置“ NULL”(字符串)
  • Set default value, like 0 or 0.0. 设置默认值,例如0或0.0。

But MIN column has the INT type and 0 or 0.0 is such a value in my case. 但是MIN列具有INT类型,在我的情况下,0或0.0是这样的值。

Here is my code: 这是我的代码:

        String HQL_QUERY = "from Tccl tccl";
        Query query = session.createQuery(HQL_QUERY);
        List<Tccl> 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 . 您应该对Tccl类的字段“ MIN”使用对象类型Integer ,而不要使用原始类型int This will allow null values. 这将允许空值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 org.hibernate.PropertyAccessException:空值已分配给布尔类型的属性 - org.hibernate.PropertyAccessException: Null value was assigned to a property of boolean type org.hibernate.PropertyAccessException:无法通过反射getter获取字段值 - org.hibernate.PropertyAccessException: could not get a field value by reflection getter of org.hibernate.PropertyAccessException持续存在 - org.hibernate.PropertyAccessException on persist org.hibernate.PropertyAccessException:使用CGLIB设置异常的属性值 - org.hibernate.PropertyAccessException: exception setting property value with CGLIB org.hibernate.PropertyAccessException:无法使用复合键设置字段值 - org.hibernate.PropertyAccessException: Could not set field value with Composite Key 嵌套的异常是org.hibernate.PropertyAccessException:无法设置字段值 - nested exception is org.hibernate.PropertyAccessException: Could not set field value 错误:-org.hibernate.PropertyAccessException:无法通过反射获取器获取字段值 - Error :- org.hibernate.PropertyAccessException: could not get a field value by reflection getter 如何修复org.hibernate.PropertyAccessException:无法通过反射设置器设置字段值 - How to fix org.hibernate.PropertyAccessException: Could not set field value value by reflection setter of 休眠:org.hibernate.PropertyAccessException:IllegalArgumentException - Hibernate : org.hibernate.PropertyAccessException: IllegalArgumentException Hibernate Criteria - org.hibernate.PropertyAccessException:IllegalArgumentException - Hibernate Criteria - org.hibernate.PropertyAccessException: IllegalArgumentException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM