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