I am writing a web application and am trying to let users updated the employee and team objects. The gist of the situation is that the team object contains a Set of employee Objects and a reference to another Employee Object ( the team leader).
I am trying to have the user submit the team object id and the id of the employee who is to be the team leader.
I can load the team without any errors, but when I try to load the employee hibernate is telling me that the object with that id has already been loaded by the session. I know the problem is that the Employee I am trying to setup as the teamLeader is already a member of the Team and is therefore being loaded by hibernate, but I am not certain how to overcome this problems.
Does anyone have any suggestions as to how I can get a reference to both objects, the team and the employee, at the same time without generating this error?
Code:
<hibernate-mapping>
<class name="us.ks.k12.topeka.serviceRequest.businessObjects.BaseBusinessObject" table="sr_bbo">
<id column="id" name="id" type="long">
<generator class="sequence">
<param name="sequence">sr_seq_oid</param>
</generator>
</id>
<timestamp name="modificationDate"/>
<property name="creationDate" type="timestamp"/>
<property name="createdBy" length="30" />
<property name="modifiedBy" length="30" />
<joined-subclass name="us.ks.k12.topeka.serviceRequest.businessObjects.Team" table="sr_team" >
<key column="id" />
<property name="name" />
<many-to-one name="teamLeader" class="us.ks.k12.topeka.serviceRequest.businessObjects.Employee" column="team_leader" not-null="false" />
<set name="teamMembers" inverse="true" lazy="true">
<key column="team"/>
<one-to-many class="us.ks.k12.topeka.serviceRequest.businessObjects.Employee" />
</set>
<set name="assignments" inverse="true" lazy="true">
<key column="team" />
<one-to-many class="us.ks.k12.topeka.serviceRequest.businessObjects.Assignable" />
</set>
</joined-subclass>
<joined-subclass name="us.ks.k12.topeka.serviceRequest.businessObjects.Employee" table="sr_employee" >
<key column="id" />
<property name="userDN" />
<property name="firstName" />
<property name="middleName" />
<property name="lastName" />
<property name="email" />
<property name="center" />
<property name="phoneNumber" />
<property name="roomNumber" />
<property name="receiveTeamNotifications" />
<many-to-one name="team" class="us.ks.k12.topeka.serviceRequest.businessObjects.Team" column="team" not-null="false" />
<!-- NEED TO ADD SERVICE NOTIFICATIONS -->
<set name="assignments" inverse="true" lazy="true">
<key column="assignedto" />
<one-to-many class="us.ks.k12.topeka.serviceRequest.businessObjects.Assignable" />
</set>
</joined-subclass>
...