现在的位置: 首页 > 综合 > 正文

org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type sette

2018年08月18日 ⁄ 综合 ⁄ 共 451字 ⁄ 字号 评论关闭

org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type sette

数据库里amount字段值为NULL,进行对象持久化关联时,企图给对象的这个属性赋值为空,而对象实例的这个属性不能为空值,所以出现错误。【amount是int型,不能为空】

 

 解决方法:将该字段在类中的类型定义为Integer。

Integer   code和int   code的区别:
Integer是对象        code   =   null;   对象可以为空.   
int   是普通类型        不可能   =   null.       

根据在数据库里,code是可以空的,故应该映射成Integer类型的。 而且hibernate中要用包装类java.long.Integer,不要用基本类型Integer.

转载于:http://blog.csdn.net/liuyy52/article/details/7011146

抱歉!评论已关闭.