Issue Type: Bug Bug
Affects Versions: 3.6.10
Assignee: Unassigned
Created: 13/May/13 2:42 AM
Description:

After upgrading from Hibernate 3.5.6 to 3.6.10 Criteria.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() {
     return this.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() {
      return this.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() {
    return this.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() {
     return this.B;
   }

  public void setB(B b) {
    this.b = b;
  }

  @Column
  public String 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

{
  "A": {
    b: { 
      cs: [{...}]
    }
  },
  "B":{
    cs: [{...}]
  },
  "Cs": [{...}]
} 

But now in 3.6.10 it looks like this

{
  "A": {
    b: { 
      cs: null
    }
  },
  "B":{
    cs: null
  },
  "Cs": [{...}]
}     

You can see the @OneToMany is not included any more.

Any help how I can achieve the old behavior is much appreciated.

Project: Hibernate ORM
Priority: Major Major
Reporter: jeremy solarz
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