-->
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.  [ 2 posts ] 
Author Message
 Post subject: StaleObjectStateException when saving a bi-directional relat
PostPosted: Thu Mar 24, 2005 8:52 pm 
Beginner
Beginner

Joined: Fri Mar 12, 2004 5:18 pm
Posts: 44
Hi,

I get a StaleObjectStateException when I try to save a bi-directional relationship using hibernate. I read the Item/Bid example in Hibernate in Action, and I cut-and-paste that part of the mapping in my code, but I still get this StaleObjectStateException.

Can someone please tell me what did I miss? I really appreciate any help.


Code:
WARNING: An operation failed due to stale data
net.sf.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) for db.model.Cookie instance with identifier: 0
   at net.sf.hibernate.persister.AbstractEntityPersister.check(AbstractEntityPersister.java:513)
   at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:664)
   at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:621)
   at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:52)
   at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2449)




Code:

UserDAO userDAO= new UserDAO();
        User user = new User();
        user.setUserName("abc");
        Data data = new Data();
        data.setUser(user);
        user.getAllData().add(data);
        userDAO.makePersistent(user);


Code:

<class name="User" table="USER" lazy="true">
      <cache usage="read-write" />

      <id name="id" type="long" column="ITEM_ID"
         unsaved-value="null" access="db.DirectSetAccessor">
         <generator class="native" />
      </id>
         
<bag    name="allData"
         cascade="all"
         inverse="true"
         
         lazy="true"
         access="db.DirectSetAccessor">
      <key>
            <column name="ITEM_ID" not-null="true"/>
        </key>
      <one-to-many class="Data"/>
   </bag>
   


   </class>


Code:
   <class name="Data" table="DATA" lazy="true">

<many-to-one
            name="user"
            class="User"
            column="ITEM_ID"
            update="false"
            cascade="none"
            not-null="true"
            outer-join="false"
            access="db.DirectSetAccessor"
            foreign-key="FK1_ITEM_ID"/>
   
   
   </class>



Top
 Profile  
 
 Post subject:
PostPosted: Tue May 03, 2005 11:36 am 
Newbie

Joined: Wed Dec 08, 2004 5:59 pm
Posts: 3
Location: Detroit, MI
I'm not sure, but perhaps your key generator mapping is incorrect? The error output says that your ID field had a value of zero which is rarely good.


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