I have got many-to-many relation in Part, Labour with PartsLabour as entity Class. I am able to save the relation for PartsLabour but when i retreive them for Part or Labour classes, I get the StackOverflowError. I cant figure it out, Any suggestion; Below are the mapping file and code;
Labour.hbm.xml
---------------------
<set
name="partSet"
inverse="true">
<key column="LABOUR_ID" />
<one-to-many class="com.wonder.common.PartsLabour" />
</set>
Parts.hbm.xml
------------------
<set
name="labourSet"
inverse="true">
<key column="PART_ID" />
<one-to-many class="com.wonder.common.PartsLabour" />
</set>
PartsLabour.hbm.xml
---------------------------
<many-to-one
name="part"
column="PART_ID"
not-null="true" />
<many-to-one
name="labour"
column="LABOUR_ID"
not-null="true" />
Unit Test
-----------
Session session = HibernateUtils.createNewSessionAndTransaction();
part = partsDAO.findById(1274L, false);
labour = labourDAO.findById(1416L, false);
partLabour.setPart(part);
partLabour.setLabour(labour);
partLabour.setPricePerUnit(5.25F);
partLabour.setDateStarted(Utilities.getCurrentTime().toString());
partLabour.setQuantity(200);
partLabour.setStatus("In Progress");
part.getLabourSet().add(partLabour);
labour.getPartSet().add(partLabour);
partLabourDAO.makePersistent(partLabour);
//Getting the Stack-Overflow error here.
// System.out.println("alpha:" + part);
// System.out.println("beta:" + labour);
HibernateUtils.commitTransaction(session);
I have seen one of the known Bugs (
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2277), Is it related to my problem as well.
I am bit new to the technology if there is anything on my side please suggest.