-->
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 when unique numbers are generated.
PostPosted: Fri Oct 06, 2006 11:54 am 
Newbie

Joined: Fri Oct 06, 2006 11:41 am
Posts: 1
Hibernate version : 3.0.5

Mapping documents:
<hibernate-mapping package="com.mycode">
<class name="Sequence" table="T_SEQUENCE">
<comment>The sequence table</comment>

<id name="id" column="OBJ_ID" type="integer">
<generator class="native" />
</id>

<version name="versionId" column="VER_ID" type="integer"/>

<property name="objName" column="OBJ_NAME" type="string" />
<property name="sequenceNbr" column="LAST_PRIM_KEY" type="integer" />
</class>
</hibernate-mapping>



I use Struts, Spring, Hibernate with Websphere and MS SQL Server 2000
Code:
I have several unique numbers to be created in different formats. I keep the last number created in the above table. And whenever a new one is required I get the current databse value. Set it in my other domain object which uses it after formatting it and then increment the value in the object and save it. During high loads I get the folowing exception. Let me know what is the best way to resolve this.

Some things I have thought:
Putting this block in synchorized mode -- Problem : it will slow down my applicaiton .
Putting lock in database - problem how to do that in Hibernate.

code snippet,
Sequence userSequence = configService.getSequence( Sequence.USER_ID_SEQUENCE);
domObj.setFormattedUserId("XXXXX"+orderSequence.getSequenceNbr());
userSequence.incrementSequence();
configService.saveSequence(orderSequence);



Exception:
; nested exception is :org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.mmm.ccss.core.config.Sequence#1]; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.mmm.ccss.core.config.Sequence#1]
org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.mmm.ccss.core.config.Sequence#1]; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.mmm.ccss.core.config.Sequence#1]
org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.mmm.ccss.core.config.Sequence#1]
at org.hibernate.persister.entity.BasicEntityPersister.check(BasicEntityPersister.java(Compiled Code))
at org.hibernate.persister.entity.BasicEntityPersister.update(BasicEntityPersister.java(Compiled Code))
at org.hibernate.persister.entity.BasicEntityPersister.updateOrInsert(BasicEntityPersister.java(Compiled Code))
at org.hibernate.persister.entity.BasicEntityPersister.update(BasicEntityPersister.java(Compiled Code))
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java(Compiled Code))
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java(Compiled Code))
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java(Compiled Code))
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java(Inlined Compiled Code))
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java(Compiled Code))
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java(Compiled Code))
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java(Compiled Code))
at org.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java(Compiled Code))
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java(Compiled Code))
at org.springframework.orm.hibernate3.HibernateTemplate.update(HibernateTemplate.java(Inlined Compiled Code))
at org.springframework.orm.hibernate3.HibernateTemplate.update(HibernateTemplate.java(Inlined Compiled Code))
at com.mycode.core.dao.hibernate.ConfigurationDAOImpl.saveSequence(ConfigurationDAOImpl.java(Compiled Code))
at com.mycode.core.service.ConfigurationService.saveSequence(ConfigurationService.java(Inlined Compiled Code))
at com.mmm.ccss.core.service.BaseService.generateOrderId(BaseService.java(Inlined Compiled Code))

Name and version of the database you are using: MS SQL Server 2000

_________________
Regards
Vasanth


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.