Using Hibernate 3.5.6 Final. I have a one-to-one containment relationship between Object and ObjectRetirement. ObjectRetirement has a FK to the containing Object and two other non-key, nullable fields (Version and Reason). I just converted the ObjectRetirement class from an Entity to an @Embeddable.
When saving the containing Object, the ObjectRetirement table gets properly populated. When calling get() on the Object, the ObjectRetirement instance is properly retrieved and populated IF at least one of the non-key fields are populated in the DB. But if I have persisted the ObjectRetirement with (objectIdKey, null, null), the ObjectRetirement instance is set to NULL on the Object when retrieved.
It's as if Hibernate's logic is, "well, the embedded object exists in the DB and has its FK populated but the other fields are NULL so I'm just going to set the entire ObjectRetirment object NULL".
When I was declaring ObjectRetirement as an Entity, I was able to get() it even when both fields were null. Why does Embedding the class change this? Is there an annotation to have Hibernate populate the object even though those nullable fields are null?
Here's the mapping from Object:
Code:
@Embedded
@AttributeOverrides({@AttributeOverride(name = "version", column = @Column(name = "versionid", table = "ObjectRetirement")),
@AttributeOverride(name = "reason", column = @Column(name = "reasonid", table = "ObjectRetirement")) })
public ObjectRetirementDO getObjectRetirement() {
return _objectRetirement;
}
Here's the ObjectRetirement Class highlights:
Code:
@Embeddable
public class ObjectRetirementDO extends ValueObject {
...
@Parent
@Column(name = "objectid")
public DomainObject getObject() {
return _object;
}
...
@ManyToOne(targetEntity = com.hli.le.model.persistence.internal.domain.VersionDO.class)
@JoinColumn(table = "ObjectRetirement", name = "versionid")
public VersionDO getVersion() {
return _version;
}
...
@ManyToOne(targetEntity = com.hli.le.model.persistence.internal.domain.ReasonDO.class)
@JoinColumn(table = "ObjectRetirement", name = "reasonid")
public ReasonDO getReason() {
return _reason;
}
Thanks!