Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate Embedded/Embeddable not null exception

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.

like image 442
Finbarr Avatar asked Mar 23 '11 16:03

Finbarr


Video Answer


1 Answers

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.

like image 149
axtavt Avatar answered Nov 05 '22 10:11

axtavt