• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Tomcat+Hibernate+Oracle inconsistent Primary Key

 
Praveen Kumar
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I have a strange problem with the Primary Key generation of Hibernate. The scenario is as follows ...

I have a table (PurchaseOrder) containing a SET(one-to-many) of LineItems.
The primary key generators for both of these are set to "native" and unsaved-value are set to "null".

When I do a saveOrUpdate() on PurchaseOrder object, records are inserted into the tables but with a incorrect primary key on the child table(LineItems table).

Lets assume that the primary key of PurchaseOrder object is 1. As I have some other one to many mappings in that table, it generates the primary key for those as 2 and 3. For the LineItem Object the primary key that hibernate generates is 4. But when I see the actual record in the Oracle table it shows that the primary key for LineItems is 0. I verified this by printing LineItems object and the PurchaseOrder object after the saveOrUpdate() call.

Although the PK of LineItem is unique, when I do an update on the PurchaseOrder object in a different transaction it fails because for Hibernate it still assumes that the PK of LineItem is 4.

I have been banging my head as why this problem surfaced all of a sudden. I have reseted the hibernate sequence in Oracle, Changed the generator to VM but the problem wont leave.

Any suggestions are welcome.

The exact stack trace is as follows ...

2004-09-22 18:39:38,250 [http-8080-Processor25] ERROR net.sf.hibernate.impl.SessionImpl - Could not synchronize database state with session
net.sf.hibernate.HibernateException: SQL insert, update or delete failed (row not found)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:25)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:689)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:642)
at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:52)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2414)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2368)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2236)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at synaro.b2b.po.POManager.saveOrUpdatePO(POManager.java:388)
at synaro.b2b.po.POManager.saveOrUpdateBulkPO(POManager.java:375)
at synaro.b2b.po.POCreatedEventHandler.handleEvent(POCreatedEventHandler.java:45)
at synaro.b2b.alertmonitoring.AlertUpdateManager.alertEventOccured(AlertUpdateManager.java:308)
at synaro.b2b.alertmonitoring.AlertEventManager.fireAlertEvent(AlertEventManager.java:60)
at synaro.b2b.alertmonitoring.AlertEventManager.receiveAlertEvent(AlertEventManager.java:41)
at synaro.b2b.alertmonitoring.events.AlertEvent$1.run(AlertEvent.java:85)
at synaro.b2b.alertmonitoring.events.AlertEvent.fireEvent(AlertEvent.java:88)
at synaro.b2b.alertmonitoring.events.AlertEvent.<init>(AlertEvent.java:49)
at synaro.b2b.alertmonitoring.events.POCreatedEvent.<init>(POCreatedEvent.java:41)
at synaro.b2b.alertmonitoring.events.POCreatedEvent.firePOCreatedAlert(POCreatedEvent.java:57)
at synaro.b2b.po.BulkPO.createPurchaseOrder(BulkPO.java:130)
at synaro.b2b.po.XMLPOCreator.processRequest(XMLPOCreator.java:102)
at synaro.b2b.common.XMLPOSTController.doPost(XMLPOSTController.java:53)
at synaro.b2b.common.XMLPOSTController.doGet(XMLPOSTController.java:31)
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:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at synaro.b2b.security.uaac.AccessControlFilter.doFilter(AccessControlFilter.java:168)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)
2004-09-22 18:39:38,296 [http-8080-Processor25] ERROR synaro.b2b.po.POManager - Unable to save or update purchase order
net.sf.hibernate.HibernateException: SQL insert, update or delete failed (row not found)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:25)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:689)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:642)
at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:52)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2414)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2368)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2236)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at synaro.b2b.po.POManager.saveOrUpdatePO(POManager.java:388)
at synaro.b2b.po.POManager.saveOrUpdateBulkPO(POManager.java:375)
at synaro.b2b.po.POCreatedEventHandler.handleEvent(POCreatedEventHandler.java:45)
at synaro.b2b.alertmonitoring.AlertUpdateManager.alertEventOccured(AlertUpdateManager.java:308)
at synaro.b2b.alertmonitoring.AlertEventManager.fireAlertEvent(AlertEventManager.java:60)
at synaro.b2b.alertmonitoring.AlertEventManager.receiveAlertEvent(AlertEventManager.java:41)
at synaro.b2b.alertmonitoring.events.AlertEvent$1.run(AlertEvent.java:85)
at synaro.b2b.alertmonitoring.events.AlertEvent.fireEvent(AlertEvent.java:88)
at synaro.b2b.alertmonitoring.events.AlertEvent.<init>(AlertEvent.java:49)
at synaro.b2b.alertmonitoring.events.POCreatedEvent.<init>(POCreatedEvent.java:41)
at synaro.b2b.alertmonitoring.events.POCreatedEvent.firePOCreatedAlert(POCreatedEvent.java:57)
at synaro.b2b.po.BulkPO.createPurchaseOrder(BulkPO.java:130)
at synaro.b2b.po.XMLPOCreator.processRequest(XMLPOCreator.java:102)
at synaro.b2b.common.XMLPOSTController.doPost(XMLPOSTController.java:53)
at synaro.b2b.common.XMLPOSTController.doGet(XMLPOSTController.java:31)
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:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at synaro.b2b.security.uaac.AccessControlFilter.doFilter(AccessControlFilter.java:168)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)
2004-09-22 18:39:38,312 [http-8080-Processor25] DEBUG synaro.b2b.hibernate.HibernateSession - Entering closeSession
2004-09-22 18:39:38,328 [http-8080-Processor25] ERROR synaro.b2b.po.POCreatedEventHandler - Could not create alerts for new purchase order
synaro.b2b.common.exception.DataPersistenceException: net.sf.hibernate.HibernateException: SQL insert, update or delete failed (row not found)
at synaro.b2b.po.POManager.saveOrUpdatePO(POManager.java:395)
at synaro.b2b.po.POManager.saveOrUpdateBulkPO(POManager.java:375)
at synaro.b2b.po.POCreatedEventHandler.handleEvent(POCreatedEventHandler.java:45)
at synaro.b2b.alertmonitoring.AlertUpdateManager.alertEventOccured(AlertUpdateManager.java:308)
at synaro.b2b.alertmonitoring.AlertEventManager.fireAlertEvent(AlertEventManager.java:60)
at synaro.b2b.alertmonitoring.AlertEventManager.receiveAlertEvent(AlertEventManager.java:41)
at synaro.b2b.alertmonitoring.events.AlertEvent$1.run(AlertEvent.java:85)
at synaro.b2b.alertmonitoring.events.AlertEvent.fireEvent(AlertEvent.java:88)
at synaro.b2b.alertmonitoring.events.AlertEvent.<init>(AlertEvent.java:49)
at synaro.b2b.alertmonitoring.events.POCreatedEvent.<init>(POCreatedEvent.java:41)
at synaro.b2b.alertmonitoring.events.POCreatedEvent.firePOCreatedAlert(POCreatedEvent.java:57)
at synaro.b2b.po.BulkPO.createPurchaseOrder(BulkPO.java:130)
at synaro.b2b.po.XMLPOCreator.processRequest(XMLPOCreator.java:102)
at synaro.b2b.common.XMLPOSTController.doPost(XMLPOSTController.java:53)
at synaro.b2b.common.XMLPOSTController.doGet(XMLPOSTController.java:31)
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:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at synaro.b2b.security.uaac.AccessControlFilter.doFilter(AccessControlFilter.java:168)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)
Caused by: net.sf.hibernate.HibernateException: SQL insert, update or delete failed (row not found)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:25)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:689)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:642)
at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:52)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2414)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2368)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2236)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at synaro.b2b.po.POManager.saveOrUpdatePO(POManager.java:388)
... 43 more

Thank You,

Praveen
 
Praveen Kumar
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Have any of you experience the above anytime? Any suggestions?

Thanks,

Praveen.
 
Ogi K
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you provide the code you have in your saveOrUpdatePO method?

Also, the mapping file...

My guess is that you're calling saveOrUpdate on the PurchaseOrder, with NEW LineItems attached to is, and have a cascade-all in your mapping. In this case, Hibernate will determine that you need to do an Update (because PO already exists, but will fail when trying to also updat eh LineItems, since those are brand new...but don't want to speculate...let's see your code first.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic