-->
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: Hibernate seems to be batching database updates causing....
PostPosted: Sun Oct 05, 2003 10:36 pm 
Beginner
Beginner

Joined: Wed Sep 17, 2003 10:25 am
Posts: 36
StaleObjectStateError.....

Okay, I have added my hibernate mapping below..and more explanation on this issue. I really need help with this...

I have an object lets say its called House. This object has a many to one relationship with another object called Father :).
This relationship is bi-directional. The id for Father is auto-generated using GUID. I am calling a DAO object from a session bean where the transaction is container managed and set to required.

In the web tier, I get a reference to the House object, update some fields and either add a Father, update the father or remove the Father (house.setFather(null)).

Then, I make a call to one method on a House DAO called updateHouse that handles all these calls in the following way:

updateHouse(House h){

if(h.getFather()!=null){
//we have a father
if(h.getFather().getFatherId()!=null){
//this father is being updated
session.update(h.getFather());
}else{
//this father is being created for the House
session.save(h.getFather();
}
}

//The house has other properties that could also be updated
session.update(h);
}

Now when I run this code, I get a StaleObjectStateError on the Father object telling me the following:


Problem updating House: my.package.House@2c14f9[houseId=1] and the Exception Msg is:
my.package.util.DataAccessException: net.sf.hibernate.StaleObjectStateException: Row
was updated or deleted by another transaction (or unsaved-value mapping was incorrect) for my.package.Father instance with identifier: 402880e5f805977600f807d5f42b0004

I am using Hibernate 2.0.2 and following are my mapping files:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping>

<!--
Created by Middlegen Hibernate plugin

http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->

<class
name="my.package.House"
table="SCHOOL"
proxy="my.package.House"
dynamic-update="true"
>
<meta attribute="implements">net.sf.hibernate.Lifecycle</meta>
<meta attribute="implements">net.sf.hibernate.Validatable</meta>
<id
name="houseId"
type="java.lang.Integer"
column="HOUSE_ID"
unsaved-value="null"
>
<generator class="assigned" />
</id>

<timestamp
column="user_dt"
name="userDt"
/>

<property
name="userId"
type="java.lang.String"
column="user_id"
length="8"
/>

<!-- associations -->
<!--one-to-one association to Teacher -->
<many-to-one
name="principal"
class="my.package.Father"
not-null="false"
>
<column name="principal_id" />
</many-to-one>

</class>

<class
name="my.package.Father"
table="TEACHER"
proxy="my.package.Father"
dynamic-update="true"
>
<meta attribute="implements">net.sf.hibernate.Lifecycle</meta>
<meta attribute="implements">net.sf.hibernate.Validatable</meta>
<id
name="fatherId"
type="java.lang.String"
column="FATHER_ID"
unsaved-value="none"
>
<generator class="uuid.hex" />
</id>
<property
name="name"
type="java.lang.String"
column="name"
not-null="false"
length="100"
/>
<property
name="comment"
type="java.lang.String"
column="comment"
not-null="false"
length="3500"
/>

</hibernate-mapping>


My classes were auto-generated by hbm2java. This has taken all weekend and I am not sure why Hibernate is doing this..


Top
 Profile  
 
 Post subject: Re: Hibernate seems to be batching database updates causing.
PostPosted: Mon Oct 06, 2003 10:46 am 
Regular
Regular

Joined: Mon Sep 08, 2003 4:53 am
Posts: 70
Location: Germany
abulheath wrote:
<timestamp
column="user_dt"
name="userDt"
/>


Have a look at the userDt column. You declared this column as timestamp element in the map. This causes Hibernate to compare the value of your object with the value stored at database while trying to store the object. If the value at the database is "newer", than you get the StaleObjectStateErrorException.


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.