Hibernate Embedded/Embeddable不是null异常 [英] Hibernate Embedded/Embeddable not null exception

查看:97
本文介绍了Hibernate Embedded/Embeddable不是null异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在所属类中:

...
@Embedded
private LatLon location;
...

在所引用的类中:

@Embeddable
public class LatLon implements Serializable {
    private double lat;
    private double lon;
    ...
}

当我尝试使用LatLon的空值保存所属类的实例时:

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.

我该怎么做才能在所属类中将此值设置为null?我尝试将其设置为Nullable,但没有任何效果.

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.

推荐答案

这是由于您的可嵌入类中具有double属性而导致的,因此Hibernate不会为它们生成null列.将其类型更改为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 to Double.

这篇关于Hibernate Embedded/Embeddable不是null异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆