-->
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.  [ 6 posts ] 
Author Message
 Post subject: Problem causing Object already loaded by session error.
PostPosted: Mon Oct 13, 2003 5:10 pm 
Newbie

Joined: Mon Oct 13, 2003 4:45 pm
Posts: 12
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>
...


Top
 Profile  
 
 Post subject: Still Confused
PostPosted: Tue Oct 14, 2003 2:24 pm 
Newbie

Joined: Mon Oct 13, 2003 4:45 pm
Posts: 12
I am still confused as to how to access these two Objects. Is there anyway to ask the session for the reference to an object with a specific field value( the object id ) and have it return the loaded reference?

Any help would be greatly appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 14, 2003 7:45 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
Is there anyway to ask the session for the reference to an object with a specific field value( the object id ) and have it return the loaded reference?


session.load()?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 29, 2003 12:07 pm 
Newbie

Joined: Mon Oct 13, 2003 4:45 pm
Posts: 12
gavin wrote:
Quote:
Is there anyway to ask the session for the reference to an object with a specific field value( the object id ) and have it return the loaded reference?


session.load()?


This does not do exactly what I am needing. I am using load to return the first object, but when I call load to get the second object hibernate complains that the object was already loaded by the first call to load. The question would be better asked as is there any way to return a reference to an object already loaded by a session if you have no reference to it?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 29, 2003 12:14 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
You are mistaken.

You can call load(Foo.class, id) as many times as you like.

Perhaps you were calling load(fooInstance, id) ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 29, 2003 3:51 pm 
Newbie

Joined: Mon Oct 13, 2003 4:45 pm
Posts: 12
gavin wrote:
You are mistaken.

You can call load(Foo.class, id) as many times as you like.

Perhaps you were calling load(fooInstance, id) ?


Yes, you are correct this is what I am doing. I missed that entirely in the documentation. Thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.