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.  [ 3 posts ] 
Author Message
 Post subject: one-to-many HQL & Criteria with outer-join
PostPosted: Fri Oct 22, 2004 1:52 am 
Newbie

Joined: Tue Sep 28, 2004 12:56 pm
Posts: 9
I tried one-to-many mapping with Hibernate, and query the result back using either HQL or Criteria query. I found the outer-join doesn't exactly work as it should be. Could some one give me some light? that's is expected behaviro or bug?

options: HQL
outer-join="false": correct
outer-join="true": outer-join happen, but too many states(= State x city)


options: Criteria
outer-join="false": correct
outer-join="true": outer-join not happen, result is correct.




Hibernate version:
Hibernate 2.1.6

Mapping documents:
<set name="city" lazy="true" inverse="true" cascade="all" outer-join="true" >
<key column="STATE_ID"/>
<one-to-ma

Code between sessionFactory.openSession() and session.close(): use either HQL or Criteria
// Iterator iter = session.find("from State").iterator();
// while (iter.hasNext()) {
// State state = (State) iter.next();
// Iterator cities = state.getCity().iterator();
// while (cities.hasNext()) {
// City city = (City) cities.next();
// System.out.println(city.getId()+ "city" + city.getName() );
// }
// System.out.println(state.getId() + "state" + state.getName() );
// }
Criteria crit = session.createCriteria(State.class);
List states = crit.list();
System.out.println("Size: " + states.size());
for (int i=0; i< states.size(); i++) {
State state = (State) states.get(i);
Iterator cities = state.getCity().iterator();
while (cities.hasNext()) {
City city = (City) cities.next();
System.out.println(city.getId()+ "city" + city.getName() );
}
System.out.println(state.getId() + "state" + state.getName() );
}

Full stack trace of any exception that occurs:

Name and version of the database you are using:
HSQLDB


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 22, 2004 1:30 pm 
Newbie

Joined: Tue Sep 28, 2004 12:56 pm
Posts: 9
Ok, I find partial answer. HQL ignore outer-join..I have to do it explicitily if I want it.

However, I still can not find weather the outer-join return from Criteria is correct.
I guess the outer-join for one-to-many relation was never intended for group fetching(only used for fetch one entity?).


Top
 Profile  
 
 Post subject: Well got an answer from another place.
PostPosted: Fri Oct 22, 2004 1:49 pm 
Newbie

Joined: Tue Sep 28, 2004 12:56 pm
Posts: 9
Seems this is expected behavior. Hibernate doesn't get rid of the duplication. However, it sucks a little since I have to change the code based on if I set the outer-join to be true or not.

==== Here was the answer ==
gavin
Hibernate Team

Joined: 26 Aug 2003
Posts: 3926
Location: Melbourne, Australia

Posted: Wed Sep 22, 2004 2:41 pm Post subject:

Um. It is not 33 objects, it is 33 references to the same object. Basically, there is no reason why Hibernate can do this unique-ification any more efficiently than you can do it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.