[转]Null value was assigned to a property of primitive type setter of"原因及解决方法
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[转]Null value was assigned to a property of primitive type setter of"原因及解决方法相关的知识,希望对你有一定的参考价值。
原文地址:http://blog.csdn.net/kevinzhangfei/article/details/6995316
在action请求数据的过程中报出"Null value was assigned to a property of primitive type setter of"错误,搜索之后发现是因为数据库里相应的字段为NULL。
例如:
<!--Hibernate映射文件中的字段-->
<property name="printTime" type="long"><column name="print_time"/></property>
- <!--Hibernate映射文件中的字段-->
- <property name="printTime" type="long"><column name="print_time"/></property>
其中的类型为hibernate类型,在生成的类中,printTime字段为long类型,为基本类型,不能为NULL.
解决方法:
第一种:数据库字段不设置为空;
第二种:手动修改映射文件,printTime使用Java类型Long,即type="java.lang.Long",Book类中的字段也要改为Long。同理,int为Integer.
第三种:在反向工程时使用Java类型,而不是hibernate类型。
以上是关于[转]Null value was assigned to a property of primitive type setter of"原因及解决方法的主要内容,如果未能解决你的问题,请参考以下文章
Null value was assigned to a property of primitive type setter
org.hibernate.PropertyAccessException:Null value was assigned to a property of primitive type setter
Null value was assigned to a property of primitive type setter of
hibernate.PropertyAccessException: Null value was assigned to a property of primitive type
Null value was assigned to a property of primitive type setter of。
null value was assigned to a property of primitive type setter of原因解决方法