DOM4J createQuery not eagerly fetching
I have an entity which cont开发者_Python百科ains a OneToMany relationship, with eager fetching, with a second entity. This second entity has two OneToOne relationships, with eager fetching also, to a third and fourth class. The OneToOne relationships are unidirectional.
I am calling createQuery() from a DOM4J session sending in "from entity" as the HQL. In the return I get the second entity but it contains only the IDs of the third and fourth entities instead of the complete contents. To me it looks like those third and fourth entities are not being eagerly fetched. I can't reproduce the code exactly but here is the most relevant parts.
@Entity
public class Event extends EventParent {
@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
@JoinColumn(name="eventId")
@org.hibernate.annotations.Cascade(value=org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
private Set<Pair> pairs=new HashSet<MarPair>();
}
@Entity
public class Pair extends PairParent {
@OneToOne(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
@org.hibernate.annotations.Cascade(value=org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
private Info info;
@OneToOne(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
@org.hibernate.annotations.Cascade(value=org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
private Results results;
}
@Entity
public class Info {
private String name;
private Date time;
}
@Entity
public class Results {
private String name;
private Date time;
}
Finally here is the code I am using for the query:
public void retrieve() {
String hqlQry = "from Event";
Session session = dom4JSessionFactory.getCurrentSession();
Session dom4jSession = session.getSession(EntityMode.DOM4J);
List results = dom4jSession.createQUery(hqlQuery).list();
}
As I mentioned, from this query I am getting back an integer for the value of info and results which is the key to the info and results table instead of the actual data being retrieved from the info and results table.
Relevant Information:
- Spring 2.5.4
- Hibernate 3.2.6
- Hibernate Annotations 3.3.1.GA
- dom4JSessionFactory is of type org.springframework.orm.hibernate3.LocalSessionFactoryBean
- The entity "Event" is actually the 7th class down in a class hierarchy (don't know if this matters or not)
I did leave out a lot of information hoping that it was not necessary. If there is something else you would need to venture a guess as to why it isn't working, please let me know.
Turns out this is a bug with the Hibernate version we are using. What I had to do was to change embed-xml to true after Hibernate generated the HBM files. This was done using the "replace" ant function.
精彩评论