-->
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: many-to-many producing empty Set
PostPosted: Thu Feb 05, 2004 12:54 am 
Newbie

Joined: Wed Dec 31, 2003 9:45 pm
Posts: 19
I have two objects, A and B with a link table A_B. In the hbm.xml, I have the mapping as:

<class name="A" table="A">
<id name="AID" type="string" unsaved-value="null">
<column name=AID" sql-type="varchar(100)" not-null="true"/>
<generator class="uuid.hex"/>
</id>
<set name="bs" table="A_B" cascade="save-update">
<key column="AID"/>
<many-to-many column="BID" class="B"/>
</set>
</class>

<class name="B" table="B">
<id name="BID" type="string" unsaved-value="null">
<column name=BID" sql-type="varchar(100)" not-null="true"/>
<generator class="uuid.hex"/>
</id>
<set name="as" table="A_B" cascade="save-update">
<key column="BID"/>
<many-to-many column="AID" class="A"/>
</set>
</class>

My code gets an A by doing an id search and retrieves the correct A as evidenced by a printout of its ID, but the size of the bs collection in object A is 0, even though a query of the database:

Select B.BID from A_B, B where A_B.AID='1' and A_B.BID=B.BID

produces 3 results. I would expect that Hibernate would do a similar query to get the BID's, then load the B's into the Set per the mapping, but it looks like I'm missing something. I've gotten other many-to-many's to work in the past, but I can't see the difference. Any ideas on what would cause an empty collection? There are no errors. I'm not looking for anyone to debug my code here, just some thoughts on what might cause an empty collection would help me continue my debugging.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 05, 2004 8:30 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
One side must be inverse="true"
check your pojo and the setter/getter correctness
check equals hashcode implementation

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Thanks, but...
PostPosted: Thu Feb 05, 2004 9:08 am 
Newbie

Joined: Wed Dec 31, 2003 9:45 pm
Posts: 19
Inverse='true' should only affect updates, not queries, correct? I do a query in the db, and there are entries in the link table for the A='1' case, so this shouldn't be an update issue. The entries are still there after I run my code as well, so its not like Hibernate is wiping out the entries either.

Since these are just string values, I haven't touched the hashcode implementation.

I'll take a look at the setter/getter, although I am seeing this behavior on other many-many's as well, so I was assuming I had a Hibernate property messed up.

Thanks for the suggestions!


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.