-->
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.  [ 14 posts ] 
Author Message
 Post subject: Another object was associated with this id
PostPosted: Thu Oct 02, 2003 9:21 am 
Newbie

Joined: Thu Oct 02, 2003 8:54 am
Posts: 2
This is the error I get.
I cannot find any documentation on this.
When do you get an error like this ?

net.sf.hibernate.HibernateException: Another object was associated with this id (the object with the given id was already loaded): [nl.mcb.sfa.vo.transactie.TransactieVO#0281e549f7fc8a1400f7fc931fb50001]
at net.sf.hibernate.impl.SessionImpl.doUpdate(SessionImpl.java:1281)
at net.sf.hibernate.impl.SessionImpl.update(SessionImpl.java:1159)
.....

Anyone any helpfull reaction ??

Thanks.
Geert.


MAPPINGS :
<hibernate-mapping>
<class name="nl.mcb.sfa.vo.transactie.TransactieVO"
table="transactie"
proxy="nl.mcb.sfa.vo.transactie.TransactieVO">
<id name="transactieId">
<generator class="uuid.hex"/>
</id>
<many-to-one name="klant" column="klantId"/>
<property name="klantTransactieNummer"/>
<property name="gesloten"/>
<many-to-one name="gebruiker" column="gebruikerId"/>
<property name="creatieDatum"/>
<many-to-one name="functionaris" column="functionarisId"/>
<bag name="regelGroepen"
order-by="regelGroepId"
lazy="true"
inverse="true">
<key column="transactieId"/>
<one-to-many class="nl.mcb.sfa.vo.transactie.RegelGroepVO"/>
</bag>
</class>
</hibernate-mapping>

<hibernate-mapping>
<class name="nl.mcb.sfa.vo.gebruiker.GebruikerVO"
table="gebruiker">
<id name="gebruikerId">
<generator class="uuid.hex"/>
</id>
<version column="version" name="version" type="integer" />
<property name="gebruikerNaam"/>
<property name="paswoord"/>
<property name="achternaam"/>
<property name="voornaam"/>
<property name="voorletters"/>
<property name="tussenvoegsels"/>
<property name="referentie"/>
<many-to-one name="afdeling" column="orderDefaultsId"/>
<property name="email"/>
<bag name="gebruikersGroepen"
table="GebruikerGebruikersGroep"
cascade="none">
<key column="gebruikerId"/>
<many-to-many column="gebruikersGroepId"
class="nl.mcb.sfa.vo.gebruiker.GebruikersGroepVO"/>
</bag>
<bag name="rollen" table="GebruikerRol" cascade="none">
<key column="gebruikerId"/>
<many-to-many column="rolId" class="nl.mcb.sfa.vo.gebruiker.RolVO"/>
</bag>
</class>
</hibernate-mapping>

<hibernate-mapping>
<class name="nl.mcb.sfa.vo.transactie.RegelGroepVO"
table="regelgroep"
proxy="nl.mcb.sfa.vo.transactie.RegelGroepVO">
<id name="regelGroepId">
<generator class="uuid.hex"/>
</id>
<property name="type"/>
<many-to-one name="parent" column="parentId"/>
<property name="active"/>
<many-to-one name="transactie" column="transactieId"/>
<many-to-one name="creator" column="creatorId"/>
<many-to-one name="owner" column="ownerId"/>
<property name="orderVrij"/>
<property name="emcebisOrderNr"/>
<property name="orderNr"/>
<property name="uitprijzen"/>
<property name="orderDate"/>
<property name="orderBevestiging"/>
<property name="kleineOrderBijdrage"/>
<property name="controleOrder"/>
<property name="automatischGoedkeuren"/>
<property name="in1ZendingLeveren"/>
<bag name="regels" order-by="afgewezen" lazy="true" inverse="true">
<key column="regelGroepId"/>
<one-to-many class="nl.mcb.sfa.vo.transactie.RegelVO"/>
</bag>
<property name="reminderDate"/>
<many-to-one name="bestelwijze" column="bestelwijzeId"/>
<many-to-one name="typeOrder" column="typeOrderId"/>
<many-to-one name="afleverAdres" column="afleveradresId"/>
<property name="orderNrKlant"/>
<property name="orderVrijgaveDate"/>
</class>
</hibernate-mapping>

<hibernate-mapping>
<class name="nl.mcb.sfa.vo.transactie.RegelVO"
table="regel"
proxy="nl.mcb.sfa.vo.transactie.RegelVO">
<id name="regelId">
<generator class="uuid.hex"/>
</id>
<many-to-one name="aantalEenheid" column="aantalEenheidId"/>
<many-to-one name="prijsEenheid" column="prijsEenheidId"/>
<property name="garantie"/>
<property name="interneTekst"/>
<property name="externeTekst"/>
<property name="algemeneTekst"/>
<many-to-one name="artikel" column="artikelId"/>
<many-to-one name="afleverAdres" column="afleverAdresId"/>
<property name="klantArtikelNr"/>
<many-to-one name="laadcode" column="laadcodeId"/>
<many-to-one name="vervoerscode" column="vervoerscodeId"/>
<many-to-one name="pickcode" column="pickcodeId"/>
<many-to-one name="aardLevering" column="aardLeveringId"/>
<property name="leverTermijn"/>
<property name="gewogenGewicht"/>
<many-to-one name="herkomst" column="herkomstId"/>
<property name="hoofdGroep"/>
<property name="subGroep"/>
<property name="restant"/>
<property name="omschrijving"/>
<many-to-one name="regelGroep" column="regelGroepId"/>
<property name="afgewezen"/>
<property name="expeditie"/>
<property name="reserveren"/>
<property name="prijsDefinitief"/>
<property name="prijsTotaal"/>
<property name="gratisLevering"/>
<property name="notitie"/>
<property name="korting"/>
<property name="kortingInPercentage"/>
<many-to-one name="kortingEenheid" column="kortingEenheidId"/>
<property name="orderNrKlant"/>
<many-to-one name="gebruiker" column="gebruikerId"/>
<property name="aantalWerkdagen"/>
<many-to-one name="redenAfwijzing" column="redenAfwijzingId"/>
<many-to-one name="betalingswijze" column="betalingswijzeId"/>
<property name="btwBerekenen"/>
<many-to-one name="eenheidPer" column="eenheidPerId" />
<bag name="regelBewerkingen" order-by="volgorde" lazy="true" inverse="true">
<key column="regelId"/>
<one-to-many class="nl.mcb.sfa.vo.transactie.RegelBewerkingVO"/>
</bag>
<bag name="regelDocumenten" order-by="regelDocumentId" lazy="true" inverse="true">
<key column="regelId"/>
<one-to-many class="nl.mcb.sfa.vo.transactie.RegelDocumentVO"/>
</bag>
<bag name="regelVarias" order-by="regelVariaId" lazy="true" inverse="true">
<key column="regelId"/>
<one-to-many class="nl.mcb.sfa.vo.transactie.RegelVariaVO"/>
</bag>
<bag name="regelVerpakkingen" order-by="regelVerpakkingId" lazy="true" inverse="true">
<key column="regelId"/>
<one-to-many class="nl.mcb.sfa.vo.transactie.RegelVerpakkingVO"/>
</bag>
</class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 02, 2003 10:40 am 
Senior
Senior

Joined: Tue Sep 23, 2003 8:18 am
Posts: 137
Location: Johannesburg, South Africa
Just guessing, from the look of the exception.

Somewhere you are assigning the primary key to one of your objects before you save it, as hibernate is performing an update (see the stacktrace).

Are you saving a new record? or Trying to update an existing one? If you are saving a new one, then somewhere, an already existing primary key is being assigned to your new record.

-G


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 02, 2003 10:45 am 
Newbie

Joined: Thu Oct 02, 2003 8:54 am
Posts: 2
You get this error if you want to create an object that already existed in the db.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 02, 2003 11:51 am 
Regular
Regular

Joined: Mon Sep 08, 2003 4:53 am
Posts: 70
Location: Germany
Why do you want to create an existing object? Why you don't load it?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 02, 2003 4:11 pm 
Newbie

Joined: Thu Oct 02, 2003 2:38 pm
Posts: 7
Location: Charlotte, NC
My understanding is that you see this error when you have loaded an object twice (2 different ways) in the same Hibernate session.

see http://www.hibernate.org/117.html#A19


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 06, 2003 4:53 am 
Newbie

Joined: Mon Oct 06, 2003 4:42 am
Posts: 1
Regarding http://www.hibernate.org/117.html#A19 :
We are facing the same problem. evict() is no option in our case because we don't have a reference to the object to be evicted. So I would like to discuss the following possible approaches:
By telling hibernate explicitly that it is ok to update the object in question hibernate should execute the update even if there is another instance with the same key (e.i. identity) in memory. I as app developer know that this other object will never be updated but only used for a view.

This could be another approach: to specify *instances* as read-only.

We desperately need this or another solution and actually we have a feeling that it is a quite common problem.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 06, 2003 6:05 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
thilo.s wrote:
evict() is no option in our case because we don't have a reference to the object to be evicted

A
Code:
session.load(MyClass.class, updatable.object.getId());
will give the reference to evict. This is a very unefficient way.

A better approche is not to have to evict (no update with other instance when object is already loaded).


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 06, 2003 2:50 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
evict() is no option in our case because we don't have a reference to the object to be evicted.


So use clear() instead.

Quote:
So I would like to discuss the following possible approaches:
By telling hibernate explicitly that it is ok to update the object in question hibernate should execute the update even if there is another instance with the same key (e.i. identity) in memory. I as app developer know that this other object will never be updated but only used for a view.


No way. You can't imagine the kind of bug possibilities this would open up.


A note: most people who run into this problem do so because they don't understand how to use saveOrUpdate() properly. Might not be the case in your case, but it certainly IS common.


Top
 Profile  
 
 Post subject: I got the same error
PostPosted: Fri Nov 07, 2003 12:16 pm 
Regular
Regular

Joined: Wed Sep 10, 2003 7:09 am
Posts: 63
Hi,

I got the same error but i couldn't solve it with the given solutions. My case is a little different:

When the application starts, I open a session and load all object from class X. Session is than closed.

Later in application, I will want to modify one of those objects (object A), but I want to lock it first on the DB.

To lock that object, I have to load it???

Now, when I lock the object(A), i'm loading it to a new instance (B).

I change one of the properties of object A and when I saveOrUpdate the object (A), I got the following error: "Another object was associated with this id".

Questions:
- Is there anyway to lock an object without loading it?
- Is there anyway to remove the object from memory without closing the session (evict didn't work, and clear don't exists - ver 2.1b4)

Thanks,
Joao Rangel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 07, 2003 12:21 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
In 2.1:

session.lock(object, LockMode.UPGRADE);


Top
 Profile  
 
 Post subject: I got another error
PostPosted: Fri Nov 07, 2003 12:58 pm 
Regular
Regular

Joined: Wed Sep 10, 2003 7:09 am
Posts: 63
I did as you told me, and i got another error. this tima was the following message: "reassociated object has dirty collection reference".

What am i doing wrong?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 07, 2003 1:10 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
if it is dirty, use session.update(object), followed by session.lock(object, LockMode.UPGRADE).


Top
 Profile  
 
 Post subject: Ir worked :)
PostPosted: Sat Nov 08, 2003 12:09 pm 
Regular
Regular

Joined: Wed Sep 10, 2003 7:09 am
Posts: 63
It worked! I updated the object before locking it and it worked!

Thanks for your help once again,
Joao Rangel


Top
 Profile  
 
 Post subject: It worked :)
PostPosted: Sat Nov 08, 2003 12:09 pm 
Regular
Regular

Joined: Wed Sep 10, 2003 7:09 am
Posts: 63
rtIt worked! I updated the object before locking it and it worked!

Thanks for your help once again,
Joao Rangel


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