在尝试将 Scala 与 JPA 结合使用时,我将以下代码片段作为实体定义的一部分
@Column(name = "ACC_INT", nullable = true)
@BeanProperty var accInt: Double = _
一切都很好,直到我检索一些数据并收到以下异常:
org.springframework.orm.hibernate3.HibernateSystemException: Null value was assigned to a property of primitive type setter of com.jim.fi.sppa.RiskData.accInt; nested exception is org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of com.jim.fi.sppa.RiskData.accInt
....
Caused by: org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of com.jim.fi.sppa.RiskData.accInt
at ...
Caused by: java.lang.IllegalArgumentException: Can not set double field com.jim.fi..sppa.RiskData.accInt to null value
我想我明白这里发生了什么——Scala 试图将我的 Double 像对待 double 一样,但我不知道如何解决它。
最佳答案
Scala 中的
Double
实际上是 double
,原始类型。对于包装类型,请参阅java.lang.Double
。
关于Scala、JPA 和可为 null 的字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3887838/