For the following entity definition the code in org.hibernate.engine.internal.Nullability#checkNullability fails to persist with a PropertyValueException("not-null property references a null or transient value" if the property innerId is null.
This is wrong (since one of the latest 4.1.x releases). It worked with 4.1.7.
The embedded object/property innerId in the entity is optional. The constraint is: "if innerId is not null, the field value must not be null - but it is valid to omit innerId completly".
This bug prevents use of composites in both optional an mandatory way.
@Entity
public class OuterEntity {
private OuterId id;
private InnerId innerId;
@EmbeddedId
@AttributeOverrides({
@AttributeOverride(name = "value", column = @Column(name = "ID_VALUE", nullable = false))})
public OuterId getId() { return id; }
public void setId(OuterId id) { this.id = id; }
@Embedded
@AttributeOverrides({
@AttributeOverride(name = "value", column = @Column(name = "INNER_ID_VALUE"))})
public InnerId getInnerId() { return innerId; }
public void setInnerId(InnerId innerId) { this.innerId = innerId; }
}
@Embeddable
public class OuterId implements Serializable {
private UUID value;
@Type(type = "my.usertype.UUIDUserType")
public UUID getValue() { return value; }
public void setValue(UUID value) { this.value = value; }
}
@Embeddable
public class InnerId implements Serializable {
private String value;
@Basic(optional = false)
public String getValue() { return value; }
public void setValue(String value) { this.value = value; }
}
|