-->
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: StaleObjectStateException An operation failed due to stale
PostPosted: Wed Jun 22, 2005 12:32 pm 
Beginner
Beginner

Joined: Tue Apr 26, 2005 8:39 am
Posts: 34
for Version 2.1.8

Document says 16.4. Using cascading update()
//parent and child were both loaded in a previous session
parent.addChild(child);
Child newChild = new Child();
parent.addChild(newChild);
session.update(parent);
session.flush();

but I am getting "net.sf.hibernate.StaleObjectStateException An operation failed due to stale data"

net.sf.hibernate.StaleObjectStateException An operation failed due to stale data
[6/22/05 12:17:30:241 EDT] 4e7d772a StaleObjectSt W net.sf.hibernate.StaleObjectStateException TRAS0014I: The following exception was logged net.sf.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) for efi.edcs.dto.Case instance with identifier: 888888

Here is the Code
// Add new Child
// got parent from previous session
if ( parent != null ) {
System.out.println("In After session close");
i = parent.getChild().size();
System.out.println("Folder Num = "+ parent.toString());
System.out.println("child Size = "+ i);
}

session = HibernateSessionFactory.currentSession();
tx = session.beginTransaction();
// add child Data
Child child = new Child();
child.setId("888888");
child.setParent(parent);

if (parent.getChild() == null) {
parent.setChild(new HashSet());
}
parent.getChild().add(child);
System.out.println("Case count : " + parent.getChild().size());

session.update(parent);
session.flush();
tx.commit();
session.close();


<id name="id" column="id" type="xxx.xxx.persistence.StringType"
unsaved-value="-1" >
<generator class="assigned" />

<id name="id" column="id" type="xxx.xxx.persistence.StringType" unsaved-value="-1" >
<generator class="assigned" />
</id>



Only one thing I am missing is

define unsaved-value="null" or unsaved-value="negative" on a <version> or <timestamp> property mapping for the class.


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.