Null value was assigned to a property of primitive

问题描述:Null value was assigned to a property of primitive type setter  ,hibernate long型数据无法读取 hiberante读long 整型数据出错 hiberante读数据库出错 
 
错误日志:

Exception in thread "main" org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of com.zsba.AdornCompanyInfo.provinceOrderMember
    at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:85)
    at org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:337)
    at org.hibernate.tuple.entity.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:200)
    at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:3560)
    at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:129)
    at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
    at org.hibernate.loader.Loader.doQuery(Loader.java:717)

 

解决办法:

javabean.hbm.xml

 <property name="processInstanceId" type="java.lang.Long"/>

 

type="long" 改为

type="java.lang.Long"

 

private long 改为

private java.lang.Long processInstanceId;

原因:数据库字段值为NULL,long 类型不能赋值为NULL,只能为0,但有些实际应用中,如学生分数,0表示0分,NULL,则表示暂无分数所以,要不设数据字段不为NULL,要不就是用java.lang.Long.

你可能感兴趣的:(java,thread,Hibernate,xml)