Hibernate Embedded/Embeddable not null exception

眉间皱痕 提交于 2020-12-30 06:41:35

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/5408574/hibernate-embedded-embeddable-not-null-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!