-->
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.  [ 4 posts ] 
Author Message
 Post subject: StaleStateException on session.flush()?
PostPosted: Sat Apr 30, 2005 3:19 am 
Senior
Senior

Joined: Tue Mar 02, 2004 6:17 pm
Posts: 151
Hibernate 3.0.2, MySQL InnoDB dialect.

I run the following code sniplet:
Code:
    Query getConstaintThemes = session.createQuery("from " +
      Theme.class.getName() + " theme where theme.parentHibernate is not null");
    for (Object theme: getConstaintThemes.list())
    {
      Implementation typedTheme = (Implementation) theme;
      typedTheme.setParent(null);
      session.saveOrUpdate(typedTheme);
    }
    session.flush();


Basically the code is setting the foreign key to null so the row can be safely deleted. I get this exception in session.flush():

Code:
org.hibernate.StaleStateException: Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1
   at org.hibernate.jdbc.BatchingBatcher.checkRowCount(BatchingBatcher.java:92)
   at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:78)
   at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:172)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:137)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:678)
   at com.be.desktopbeautifier.servlet.InitDB.processRequest(InitDB.java:59)
   at com.be.desktopbeautifier.servlet.SingleTransactionServlet$1.run(SingleTransactionServlet.java:44)
   at com.be.desktopbeautifier.servlet.AbstractServlet.processTransaction(AbstractServlet.java:265)
   at com.be.desktopbeautifier.servlet.SingleTransactionServlet.processRequest(SingleTransactionServlet.java:40)
   at com.be.desktopbeautifier.servlet.AbstractServlet.doGet(AbstractServlet.java:240)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
   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.valves.AccessLogValve.invoke(AccessLogValve.java:526)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
   at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
   at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
   at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
   at java.lang.Thread.run(Unknown Source)


Is this a Hibernate bug of some sort in the MySQL dialect?

Gili


Top
 Profile  
 
 Post subject: Re: StaleStateException on session.flush()?
PostPosted: Sat Apr 30, 2005 3:42 am 
Senior
Senior

Joined: Tue Mar 02, 2004 6:17 pm
Posts: 151
I'm guessing this is related to the "hibernate.jdbc.batch_versioned_data" configuration value? Does this mean that the MySQL JDBC driver returns incorrect values?

Gili


Top
 Profile  
 
 Post subject: Re: StaleStateException on session.flush()?
PostPosted: Sat Apr 30, 2005 4:02 am 
Senior
Senior

Joined: Tue Mar 02, 2004 6:17 pm
Posts: 151
I set "hibernate.jdbc.batch_versioned_data" to false and now I get:

Code:
org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.be.desktopbeautifier.server.DefaultTheme#64]


This is good news because it likely means that the JDBC driver is not at fault. I think what is happening is that I was confusing a Transaction for a locking mechanism -- that is, I was assuming that while I was in mid-transaction, the underlying records were locked. I realize now that isn't necessarily true and will investigate further if the row is indeed being modified by another transaction.

Sorry I am rather new to these concepts.


Top
 Profile  
 
 Post subject: Re: StaleStateException on session.flush()?
PostPosted: Sat Apr 30, 2005 11:40 am 
Senior
Senior

Joined: Tue Mar 02, 2004 6:17 pm
Posts: 151
Ok, I've read the online reference documentation on the topic of locking and I am still a bit confused. It seems to be encouraging me to not do any manual locking and if optimistic locking causes a StaleObjectException I am supposed to refresh my objects and retry the operation (indefinately). Is this correct? Or does it make sense to do manual locking so long as it is for a well-defined small section of code?


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