-->
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: NonUniqueObjectException.
PostPosted: Mon Mar 14, 2005 10:53 am 
Newbie

Joined: Wed Jan 26, 2005 6:18 pm
Posts: 1
Hi,

My application involves 4 classes: Person, Task, Place, and Timeline.
Their relationships are as follows:
1. one Person may have many Task (one-to-many).
2. one Person may have many Place (one-to-many).
3. one Task may perform on many Timeline and in different Place. That
means one Task may have many Timeline, and one Place may be
used to perform many Timeline.

So I created the following mapping files:
in Person.hbm.xml
...
<set name="tasks" cascade="all">
<key column="tadk_personid"/>
<one-to-many class="Task"/>
</set>

<set name="places" cascade="all">
<key column="place_personid"/>
<one-to-many class="Place"/>
</set>
...
in Task.hbm.xml
...
<many-to-one name="person" class="Person" column="task_personid" cascade="all"/>

<set name="timelines" cascade="all">
<key column="timeline_taskid"/>
<one-to-many class="Timeline"/>
</set>
...
in Place.hbm.xml
...
<many-to-one name="person" class="Person" column="place_personid" cascade="all"/>
...
in Timeline.hbm.xml
...
<property name="startDate" type="java.util.Date" column="timeline_startdate"/>

<many-to-one name="task" class="Task" column="timeline_taskid" cascade="all"/>

<many-to-one name="place" class="Place" column="timeline="placeid" cascade="all"/>
...

I don't want to get a set of Timelines from a Place, so there is no one-to-many set in the Place.hbm.xml.

The propblem is when I try to save a new Timeline, I always got the NonUniqueObjectException. :(
my codes are as follows. (I use the HibernateHelper and DAO to do
the hibernate operation.):
...
Timeline newTime = new TimeLine();
newTime.setStartDate(new Date());
newTime.setTask(DAOFactory.getTaskDAO().getTask(taskId));
newTime.setPlace(DAOFactory.getPlaceDAO().getPlace(placeId));
DAOFactory.getTimelineDAO().saveOrUpdate(newTime);
....

Hibernate version: 2.1.6

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:
net.sf.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: 1, of class: Task

Name and version of the database you are using:
MySQL 4.0.18


I spent weeks in this issue! I am so frustrated! :(

Any suggestion is appratiated.

Thanks.


Sean


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.