After upgrading from Hibernate 3.5.6 to 3.6.10Criteria.ALIAS_TO_ENTITY_MAP behaves differently. @ManyToOne relations are still included in the original entity, but for @OneToMany relations objects are not included in the owning entity.
Example:
A -> B
public class A {
private B b;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "b_id")
public B getB() {
returnthis.B;
}
public void setB(B b) {
this.b = b;
}
}
B -> C
public class B {
private Set<A> as;
private Set<C> cs;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "b")
public Set<A> getAs() {
returnthis.as;
}
public void setAs(Set<A> as) {
this.as = as;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "b", orphanRemoval=true)
@Cascade({ CascadeType.ALL })
public Set<C> getCs() {
returnthis.cs;
}
public void setCs(Set<C> cs) {
this.cs = cs;
}
}
C -> B
public class C {
private B b;
pirvate String filter
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "b_id")
public B getB() {
returnthis.B;
}
public void setB(B b) {
this.b = b;
}
@Column
publicString getFilter(){
return filter;
}
public void setFilter(String filter){
this.filter = filter;
}
}
Using Spring HibernateDaoSupport for creating a "root" criteria object the statements look like this:
// this inherits from HibernateDaoSupport
Criteria criteria = this.getSession().createCriteria(A.class,"A");
criteria.
createCriteria("A.b","B",CriteriaSpecification.LEFT_JOIN).
createCriteria("B.cs","Cs",CriteriaSpecification.LEFT_JOIN).
add(Restrictions.eq("Cs.filter", filter)).
setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
the resulting SQL looks like this (column names are left out for the sake of brevity)
select a.*, b.*, c.* from A
left outer join B on A.b_id = B.id
left outer join C on B.id = C.b_id
In Hibernate 3.5.6 the result (in JSON syntax) was like this
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira