-->
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: Problem with version column generated by database
PostPosted: Thu Mar 22, 2007 8:47 am 
Newbie

Joined: Thu Apr 27, 2006 5:51 am
Posts: 5
Hi all,

we were working for quite some time with hibernate 3.1.0 using version columns with values generated by a database trigger for optimistic locking.
Due to Bug HHH-1750 we have to update to a newer Version of hibernate (i.e. 3.2.2).
Now all updates are failing with StaleObjectStateExceptions.
I did some debugging and found
Code:
      if ( persister.isVersionPropertyGenerated() ) {
         // we need to grab the version value from the entity, otherwise
         // we have issues with generated-version entities that may have
         // multiple actions queued during the same flush
         previousVersion = persister.getVersion( instance, session.getEntityMode() );
      }

in the EntityUpdateAction wich is new (from 3.1.0 to 3.2.2) and imho is the reason for the Exceptions we see.

Even though, I don't think this piece of code shouldn't be there. It simply forces an existing misbehaviour out into the sunlight. I would like to know, why hibernate increases the version in the entity at all, when it is mapped with generated="always". It happens in the DefaultFlushEntityEventListeners getNextVersion method called upon flush from the scheduleUpdateMethod. I'd expect this only to happen, if the generated attribute is set to never.

Did anybody encounter the same problem? Is this a bug or a intended behaviour of hibernate? If it is the later could somebody please explain the intention?

I found one similiar posting without any reply in this forum (http://forum.hibernate.org/viewtopic.php?t=968644&sid=c4834a123fd66e30379f0e579ddef081). The workaround described there seems to work for us, but thats kind of unsatisfying.

Any Help would be appreciated
Thanx Dr. Z

Hibernate version: 3.2.2

Mapping documents:
Code:
<hibernate-mapping>
   <class name="de.fhg.sigma.webzeb.pojo.ZewPos" table="ZEW_POS"
      select-before-update="true">
      <id name="sysIsn" type="de.fhg.sigma.commons.type.SysIsnType">
         <column name="SYS_ISN" />
         <generator
            class="de.fhg.sigma.commons.persistence.SysIsnGenerator">
            <param name="sequence">SYS_SEQUENCE</param>
         </generator>
      </id>
      <version column="SYS_VERSION" name="sysVersion" type="java.lang.Long"
         generated="never" insert="true"/>
(... ommited the other properties as they are of no importance...)
   </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Just a plain session.saveOrUpdate(zeb);
Full stack trace of any exception that occurs:
Code:
de.fhg.sigma.commons.persistence.DataAccessException: Fehler im Commit der Transaktion
        at de.fhg.sigma.commons.persistence.SessionProvider.commitTransaction(SessionProvider.java:338)
        at de.fhg.sigma.webzeb.usecasecontroller.ZebReleaseController.release(ZebReleaseController.java:109)
        at de.fhg.sigma.webzeb.usecasecontroller.ZebReleaseController$$EnhancerByCGLIB$$894e8921.CGLIB$release$0(<generated>)
        at de.fhg.sigma.webzeb.usecasecontroller.ZebReleaseController$$EnhancerByCGLIB$$894e8921$$FastClassByCGLIB$$90b62785.invoke(<generated>)
        at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:167)
        at de.fhg.sigma.webzeb.security.AuthorizationInterceptor.intercept(AuthorizationInterceptor.java:58)
        at de.fhg.sigma.webzeb.usecasecontroller.ZebReleaseController$$EnhancerByCGLIB$$894e8921.release(<generated>)
        at de.fhg.sigma.webzeb.businessDelegate.ZebManagerBDImpl.release(ZebManagerBDImpl.java:100)
        at de.fhg.sigma.webzeb.struts.action.CreateZebAction.releaseZebs(CreateZebAction.java:404)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:274)
        at de.fhg.sigma.webzeb.struts.action.BaseLookupDispatchAction.dispatchMethod(BaseLookupDispatchAction.java:480)
        at org.apache.struts.actions.LookupDispatchAction.execute(LookupDispatchAction.java:160)
        at de.fhg.sigma.webzeb.struts.action.BaseLookupDispatchAction.execute(BaseLookupDispatchAction.java:109)
        at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
        at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
        at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
        at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
        at org.apache.catalina.valves.RequestFilterValve.process(RequestFilterValve.java:275)
        at org.apache.catalina.valves.RemoteAddrValve.invoke(RemoteAddrValve.java:80)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
        at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:199)
        at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:282)
        at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:744)
        at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:674)
        at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:866)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
        at java.lang.Thread.run(Thread.java:595)
Caused by: org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [de.fhg.sigma.webzeb.pojo.ZewKopf#230685684080]
        at org.hibernate.persister.entity.AbstractEntityPersister.check(AbstractEntityPersister.java:1761)
        at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2403)
        at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2303)
        at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2603)
        at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:92)
        at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
        at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
        at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
        at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
        at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
        at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
        at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
        at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
        at de.fhg.sigma.commons.persistence.SessionProvider.commitTransaction(SessionProvider.java:334)
        ... 39 more

Name and version of the database you are using:
Oracle 9i


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.