This question is similar to Pete_Gore's but for spring hibernate. I want to create an Entity with an Embedded object which the Embedded object can be nullable, but if it is defined then the properties in the Embedded object should be non-nullable.
Entity.java
@Entity
public class EntityObject {
@Column
private String name;
@Embedded
private EmbeddedObject embeddedObject;// This should be nullable
//Getters, setters, and constructor
}
Embedded.java
@Embeddable
public class EmbeddedObject {
@Column(nullable = false)
private String exampleProperty;// This should be non-nullable
//Getters, setters, and constructor
}
This scenario works when exampleProperty is nullable but when I set it to be non-nullable I get an error similar to the following when creating an EntityObject with a null EmbeddedObject.
NULL not allowed for column "exampleProperty"; SQL statement: