-->
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.  [ 1 post ] 
Author Message
 Post subject: Many-To-Many same class problem
PostPosted: Sat Jan 15, 2011 6:39 am 
Newbie

Joined: Sat Dec 11, 2010 8:49 am
Posts: 19
Hello,

I needed to create many-to-many relation between boss and employee which are
instances of same class. Every boss can have one or more employees and vice versa.
I created two tables, one operator table which holds data of operator and
second table hierarchy to mantain relation between them.
I created many-to-many relation in hibernate like this:

<set name="bosses" inverse="true" lazy="true" table="hierarchy" fetch="select">
<key>
<column name="EmployeeID" not-null="true" />
</key>
<many-to-many column="ManagerID" class="operator" />
</set>
<set name="employees" inverse="true" lazy="true" table="hierarchy" fetch="select">
<key>
<column name="ManagerID" not-null="true" />
</key>
<many-to-many column="EmployeeID" class="operator" />
</set>

Everything works fine except one thing. When i add record to hierarchy table i got
set of bosses updated in all operators but set of employees is not updated for some reason.
I persist hierarchy like this:
Hierarchy hierarchy = new Hierarchy(employee.getOperatorId(), boss.getOperatorId());
HierarchyDAO.persist(hierarchy);

What is strange is when i restart application, everything looks fine and both sets are updated properly.

I tried to add manually employee to boss every time when i persist hierarchy object with:
boss.getEmployees().add(operator);
and it works but i doubt it is needed.

Does someone have idea what i am doing wrong.

Best regards.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.