Hibernate Embedded/Embeddable 不为空异常
在所属类中:
...
@Embedded
private LatLon location;
...
在引用的类中:
@Embeddable
public class LatLon implements Serializable {
private double lat;
private double lon;
...
}
当我尝试使用 LatLon
的 null 值保存所属类的实例时:
org.hibernate.PropertyValueException:not-null 属性引用 a null 或瞬态值:com.*.location
。
我该怎么做才能允许该值在所属类中为空?我尝试将其设置为可为空,但没有效果。
In the owning class:
...
@Embedded
private LatLon location;
...
In the referenced class:
@Embeddable
public class LatLon implements Serializable {
private double lat;
private double lon;
...
}
When I try to save an instance of the owning class with a null value for LatLon
:
org.hibernate.PropertyValueException: not-null property references a null or transient value: com.*.location
.
What can I do to allow this value to be null in the owning class? I have tried making it Nullable
and that had no effect.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为您的嵌入类中有 double 属性,因此 Hibernate 会为它们生成非空列。将它们的类型更改为
Double
。It's caused by the fact that you have
double
properties in your embeddable class, so that Hibernate generates not null columns for them. Change their types toDouble
.