-->
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.  [ 7 posts ] 
Author Message
 Post subject: Lists not returning expected content
PostPosted: Wed Nov 09, 2005 11:10 am 
Newbie

Joined: Fri Oct 21, 2005 4:49 am
Posts: 13
Hibernate version:
3.0.5
Name and version of the database you are using:
MySQL 4.1.14

At the beginning and end of each JSP page in my application, I open and close the Hibernate session using the HibernateUtil class from the book with ThreadLocals.

Everything works except lists on the join table of a many to many relationship. I have another m-n join table which does work, but the broken one, AonB, alos contains extraInformation. The mapping files are set up so that As have a many to many to Bs and vice versa AND both As and Bs each have a one to many relation to As on Bs.

When fetching a list using
Code:
createQuery("from AonB").list();// OR
createQuery("from AonB where aid=:aid").setString("aid", getAID()).list();

a list of the correct size (I can check the DB with mySQL Query Browser, so I know DB is correct) is returned but the list contains duplicates and hence not all the correct lines....?!

Any help greatly appreciated


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 12:28 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
correct me if I'm wrong, but isn't a join on a many to many relatoinship going to return lots of repeat data?

If this is being returned as a List of Arrays of Objects (one array of object for each satisfied join condition containing one object A and one object B), you will get many copies of A per each B it matches up with.

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 12:36 pm 
Newbie

Joined: Fri Oct 21, 2005 4:49 am
Posts: 13
When I say join table, I may have used incorrect terminology.
It's just a table with 3 columns, 2 foreign keys and the extra information to relate 2 other tables.

"from AonB" should return all the rows in the table and it does return a list of the right size...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 1:27 pm 
Senior
Senior

Joined: Mon Apr 04, 2005 8:04 am
Posts: 128
Location: Manchester, NH USA
Mapping file(s)?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 10, 2005 9:12 am 
Newbie

Joined: Fri Oct 21, 2005 4:49 am
Posts: 13
The mapping files can be seen here:
http://forum.hibernate.org/viewtopic.php?p=2267520#2267520

Maybe I should point out that I do have a class AonB to represent the items in the AonB table. I'm also using java5 and forcing the output from the list() method into a List<AonB> which raises an unchecked warning from the compiler.

Same problem with Hibernate 3.1 rc2 too.

Thanks for your help


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 11, 2005 4:48 am 
Newbie

Joined: Fri Oct 21, 2005 4:49 am
Posts: 13
Using the createSQLQuery(...) method has no effect either.

I assume that it can't be a bug in Hibernate becuase it would be really serious and someone would've fixed it already.
Could it be something to do with lazy loading? But I don't have this problem doing the exact same code on other tables...

Therefore I suspect the rather dodgy mapping file for AonB which middlegen generated. However, this file does work in all other cases whereas any 'correct' manually edited versions of the file do not initialise.


Top
 Profile  
 
 Post subject: breakthrough!
PostPosted: Fri Nov 11, 2005 7:21 am 
Newbie

Joined: Fri Oct 21, 2005 4:49 am
Posts: 13
Aha! It's not random, it's becuase it's using the extraInfo as the key instead of the 2 FKs.

This is due to the middlegen generated mapping file (see link above). I have tried to fix this in the past, but to no avail. Any ideas?


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