-->
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.  [ 3 posts ] 
Author Message
 Post subject: problem while saving a class with composite-id
PostPosted: Fri Jul 23, 2004 7:18 pm 
Beginner
Beginner

Joined: Fri Jan 16, 2004 3:22 pm
Posts: 26
Hello

there is this error i am having during creation of a class with a composite-id, an exception occurrs:

Code:
17:28:10,093 ERROR SessionImpl:2368 - Could not synchronize database state with session
net.sf.hibernate.HibernateException: SQL insert, update or delete failed (row not found)
        at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:25)
        at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:687)
        at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:640)
...


the thing is i am pretty sure both of the components of the class are saved before the composite, here is what i'm doing, hope anyone could help me on this :

Code:
<class name="A_B" table="A_B" >
    <composite-id name="comp_id" class="ilce.enciclomedia.dominio.TuplaAD_RSPK">
        <key-many-to-one name="a" class="A" >
           <column name="idA" />
       </key-many-to-one>
      <key-many-to-one name="b" class="ilce.enciclomedia.dominio.TuplaMC_RS" >
           <column name="idB" />
       </key-many-to-one>
    </composite-id>
</class>


Code:
// instance of A already exist in db
A a = (A)session.load(A.class,idA) ;
//instance of B is new
B b = (B)session.load(B.class,idB) ;
//new A_B
A_B ab = new A_B( new comp_id(a, b) ) ;
session.saveOrUpdate(a) ;
session.saveOrUpdate(b) ;
//the A_B are 'accesible' from A, and B, so i have also tried putting this here:
//a.getA_Bs().add(ab);
//b.getA_Bs().add(ab);
session.saveOrUpdate(ab) ; //this fails as described above

that wasn't exactly the code because i'm using spring so each call to session.saveOrUpdate get a session using AOP

could someone point me where i'm doing wrong or something i'm missing

thanks in advance!
Gerardo


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 23, 2004 7:49 pm 
Beginner
Beginner

Joined: Wed Jul 21, 2004 12:28 pm
Posts: 27
Location: New York
well you have to use either update or save since you have composite id.

the other alternative is to use interceptor and specify what the record is about. So if you retrieved the record from the database set its status as existing and when saveOrUpdate is called the interceptor should look up the value to determine whether an update or insert has to be issued.

look up composite ids in the reference manual more careful I believe there is a reference to the fact.

alex.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 25, 2004 9:35 pm 
Beginner
Beginner

Joined: Fri Jan 16, 2004 3:22 pm
Posts: 26
i have checked the docs but haven't no specific info about this.

my point is that, in the code above i'm saving the a and b instances of the composite-id just before saving the class with the composite-id, so why is it complaining of the row not found??


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