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

这个异常就是说int类型是不能赋值为null的,而Integer可以。

在mysql数据库中我们设置了int可以为null,则在我的modle类和映射文件就应该使用Integer类型。

这个和java5的自动拆箱装箱还不是一回事。

 Integer i = 3;  //自动装箱  
        int a = i + 3;  //自动拆箱  

拆箱时需要注意空指针异常(NullPointerException)!

           如:  Integer x=null;
                  int y=x;


解决:


把原来的

 <property name="cookie_id" type="int">
            <column name="cookie_id" />
        </property>

修改为

 <property name="cookie_id" type="java.lang.Integer">
            <column name="cookie_id" />
        </property>


modle类也要改为:

private Integer cookie_id;




org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of modle.Member.cookie_id
	org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:109)
	org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:352)
	org.hibernate.tuple.entity.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:232)
	org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:3580)
	org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:152)
	org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:877)
	org.hibernate.loader.Loader.doQuery(Loader.java:752)
	org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
	org.hibernate.loader.Loader.doList(Loader.java:2232)
	org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2129)
	org.hibernate.loader.Loader.list(Loader.java:2124)
	org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:401)
	org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
	org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
	org.hibernate.impl.SessionImpl.list(SessionImpl.java:1149)


你可能感兴趣的:(org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type sette)