Unexpected behavior with association which overrides a transient property in Hibernate
Issue
- An entity hierarchy is defined as follows:
@MappedSuperclass
public class SuperClass implements Serializable {
...
@Transient
public RelatedEntity getRelatedEntity() {
return relatedEntity;
}
}
@Entity
public class SubClass extends SuperClass {
@ManyToOne(targetEntity = RelatedEntity.class, fetch = FetchType.LAZY)
@JoinColumn(name = "AssociatedId")
public RelatedEntity getRelatedEntity() {
return super.getRelatedEntity();
}
}
@Entity
public class RelatedEntity {
...
}
- Sometimes the association is found to be null. Other times it is populated automatically (e.g. when loading instances of the subclass using a query).
Environment
- Red Hat JBoss Enterprise Application Platform (EAP) 6
- Hibernate 4
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.