Null value was assigned to a property of primitive

问题描述:Null value was assigned to a property of primitive type setter ,hibernate int型数据无法读取 hiberante读int 整型数据出错 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)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1851)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:48)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:42)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3038)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:395)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:375)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:139)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:195)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:103)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:815)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:808)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
at $Proxy0.get(Unknown Source)
at com.zsba.HibernateUtil.main(HibernateUtil.java:60)
Caused by: java.lang.IllegalArgumentException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:42)
... 26 more

解决办法:

javabean.hbm.xml

<property name="provinceOrderMember" type="int">
<column name="provinceOrderMember">
<comment></comment>
</column>
</property>
type="int" 改为type="java.lang.Integer"

javabean

private int provinceOrderMember; 改为private Intege provinceOrderMember


原因:数据库字段值为NULL,int 类型不能赋值为NULL,只能为0,但有些实际应用中,如学生分数,0表示0分,NULL,则表示暂无分数所以,要不设数据字段不为NULL,要不就是用Integer.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这个错误通常是因为尝试将一个空值(null)赋值给 BluetoothDevice 类型的变量导致的。在Dart中,如果你没有明确给一个变量赋值,它的默认值将是 null。因此,在使用 BluetoothDevice 类型的变量之前,必须确保它已经被初始化为一个有效的 BluetoothDevice 对象。 以下是一些可能会导致这个错误的常见情况: 1. 没有正确初始化 BluetoothDevice 对象 在声明 BluetoothDevice 类型的变量后,必须使用 BluetoothDevice 的构造函数来初始化该变量。例如: ``` BluetoothDevice device = await FlutterBlue.instance.connect(deviceId); ``` 如果在初始化变量之前尝试使用它,将会触发 'Null' can't be assigned to a variable of type 'BluetoothDevice' 错误。 2. 从方法返回了一个空值 如果在使用 BluetoothDevice 变量之前调用了某个方法,并且该方法返回了一个空值(null),那么当尝试将其赋值给 BluetoothDevice 类型的变量时,将会触发 'Null' can't be assigned to a variable of type 'BluetoothDevice' 错误。 要解决这个问题,可以在使用 BluetoothDevice 变量之前检查它是否为空。例如: ``` if (device != null) { // 使用 BluetoothDevice 变量 } ``` 这样可以避免尝试将一个空值赋值给 BluetoothDevice 类型的变量。 总之,避免将空值赋值给 BluetoothDevice 类型的变量的最好方法是在使用它之前进行初始化,并在使用之前检查它是否为空。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值