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

在使用原生的sql查询pojo对象时候,数据库里realAmount字段值为NULL,进行对象持久化关联时,企图给对象的这个属性赋值为空,而对象实例的这个属性不能为空值,所以出现错误。【realAmount是int型,不能为空】

 

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

Integer   code和int   code的区别:
Integer是对象        code   =   null;   对象可以为空.   
int   是普通类型        不可能   =   null.       
根据在数据库里,code是可以空的,故应该映射成Integer类型的。 而且hibernate中要用包装类java.long.Integer,不要用基本类型Integer.

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

上一篇:SQLite数据库使用


下一篇:取消sqlserver 锁表