-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: DOM4J createQuery not eagerly fetching
PostPosted: Thu Jun 02, 2011 2:02 pm 
Newbie

Joined: Thu Jun 02, 2011 1:59 pm
Posts: 3
I have an entity which contains 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.

Code:
@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:

Code:
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.


Top
 Profile  
 
 Post subject: Re: DOM4J createQuery not eagerly fetching
PostPosted: Fri Jun 03, 2011 12:00 pm 
Newbie

Joined: Thu Jun 02, 2011 1:59 pm
Posts: 3
One additional piece of information: Retrieving the information using a "regular" session and createCriteria() works properly.

So why would this work and not the dom4J?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.