[英]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:
有一些解决此问题的方法:
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.