-->
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: BatchUpdateException when storing a many2many relation
PostPosted: Tue Mar 02, 2004 4:24 am 
Newbie

Joined: Wed Nov 12, 2003 12:12 pm
Posts: 2
Location: Sweden
Hello,

I get the following error when trying to create a many2many relation (it works fine when I run it in my JUint test, but not when I run it in a JBoss 3.2.3:
java.sql.BatchUpdateException: ORA-00001: unique constraint (DF_MT.XPKASSIGNED_DRIVER) violated

The code I am running is:
Code:
private void AddAssignedDriverAssignments( Collection drvList, Dfuser theDfUser, Session session )
   throws HibernateException
{
   // Add all newly assigned drivers (unless they already are assigned)
   Iterator J = drvList.iterator();
   Iterator I;
   Long uniqueId;
   boolean alreadyAssigned;
   PersonInformation   existingPers;
   PersonInformation pers;
   
   while ( J.hasNext() )
   {
      pers = (PersonInformation)J.next();
      // First check that this driver isn't already assigned to the user
      I = theDfUser.getPersonInformations().iterator();
      alreadyAssigned = false;
      while ( I.hasNext() && !alreadyAssigned )
      {
         existingPers = (PersonInformation)I.next();
         if ( existingPers.getPersonInformationId().compareTo( pers.getPersonInformationId() ) == 0 )
         {   // The current driver already is assigned to this user
            logger.debug("Tried to assign the driver with Id (" + pers.getPersonInformationId() +
                  ") to user with id (" + theDfUser.getDfuserId() + "), but this driver is already assigned to the user.");
            alreadyAssigned = true;
         }
      }
      if ( !alreadyAssigned )
      {   // The current driver isn't assigned to this user -> Assign him
         logger.debug("Assigning the driver with Id (" + pers.getPersonInformationId() +
               ") to user with id (" + theDfUser.getDfuserId() + ").");
         theDfUser.getPersonInformations().add( pers );
         pers.getDfusers().add( theDfUser );
         session.saveOrUpdate( pers );
         session.saveOrUpdate( theDfUser );
         logger.info("********* Assigning done !");
      }
   }
}


Here is an extracted portion of the Dfuser.hbm.xml (generated with Middlegen):
Code:
<!-- bi-directional many-to-many association to PersonInformation -->
<set
   name="personInformations"
   lazy="true"
   table="ASSIGNED_DRIVER"
>
   <key>
      <column name="DFUSER__ID" />
   </key>
   <many-to-many
      class="com.wirelesscar.dynafleet.model.hibernate.PersonInformation"
   >
      <column name="PERSON_INFORMATION__ID" />
   </many-to-many>
</set>


And an extracted portion of the PersonInformation.hbm.xml (generated with Middlegen):

Code:
<!-- bi-directional many-to-many association to Dfuser -->
<set
   name="dfusers"
   lazy="true"
   table="ASSIGNED_DRIVER"
>
   <key>
      <column name="PERSON_INFORMATION__ID" />
   </key>
   <many-to-many
      class="com.wirelesscar.dynafleet.model.hibernate.Dfuser"
   >
      <column name="DFUSER__ID" />
   </many-to-many>
</set>


I also tried to remove the following part from the code (but I get the same error). (It feels as one only should have to add the relation on one side, but I don't know if this is the way it works).
Code:
pers.getDfusers().add( theDfUser );
session.saveOrUpdate( pers );


It does work if I remove the flush()-call in my code (which is done by the function which calls the one above), but if I use flush it crashes when closing the hibernate transaction !

Here is part of the error I get
Code:
2004-03-02 08:57:16,456 DEBUG [net.sf.hibernate.util.JDBCExceptionReporter] SQL Exception
java.sql.BatchUpdateException: ORA-00001: unique constraint (DF_MT.XPKASSIGNED_DRIVER) violated

   at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:458)
   at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:3907)
   at org.jboss.resource.adapter.jdbc.WrappedStatement.executeBatch(WrappedStatement.java:701)
   at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
   at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:122)
   at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2385)
   at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2338)
   at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2204)
   at com.wirelesscar.dynafleet.fleetmanager.ejb.UserManagerDao.synchronizeAssignedDriversForUser(UserManagerDao.java:639)
   at com.wirelesscar.dynafleet.fleetmanager.ejb.UserManagerBean.synchronizeAssignedDriversForUser(UserManagerBean.java:201)
   at com.wirelesscar.dynafleet.fleetmanager.ejb.UserManagerSession.synchronizeAssignedDriversForUser(UserManagerSession.java:238)
   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:324)
   at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:683)
   at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:185)
   at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:72)
   at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:84)
   at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:267)
   at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:128)
   at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:118)
   at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:191)
   at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
   at org.jboss.ejb.StatelessSessionContainer.internalInvoke(StatelessSessionContainer.java:331)
   at org.jboss.ejb.Container.invoke(Container.java:700)
   at org.jboss.ejb.plugins.local.BaseLocalProxyFactory.invoke(BaseLocalProxyFactory.java:375)
   at org.jboss.ejb.plugins.local.StatelessSessionProxy.invoke(StatelessSessionProxy.java:83)
   at $Proxy493.synchronizeAssignedDriversForUser(Unknown Source)
   at com.wirelesscar.dynafleet.fleetmanager.impl.UserManagerDelegate.synchronizeAssignedDriversForUser(UserManagerDelegate.java:249)
   at com.wirelesscar.dynafleet.fleetmanager.impl.UserManagerDelegate$$EnhancerByCGLIB$$12107efe.CGLIB$$ACCESS_synchronizeAssignedDriversForUser_8(<generated>)
   at com.wirelesscar.dynafleet.fleetmanager.impl.UserManagerDelegate$$EnhancerByCGLIB$$12107efe$$FastClassByCGLIB$$d0a7c4b8.invoke(<generated>)
   at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:201)
   at com.wirelesscar.dynafleet.common.impl.BaseInterceptor.intercept(BaseInterceptor.java:86)
   at com.wirelesscar.dynafleet.fleetmanager.impl.UserManagerDelegate$$EnhancerByCGLIB$$12107efe.synchronizeAssignedDriversForUser(<generated>)
   at com.wirelesscar.dynafleet.application.web.action.AssignAction.doSave(AssignAction.java:484)
   at com.wirelesscar.dynafleet.application.web.action.AssignAction.execute(AssignAction.java:60)
   at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
   at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
   at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
   at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
   at org.jboss.web.tomcat.security.JBossSecurityMgrRealm.invoke(JBossSecurityMgrRealm.java:220)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
   at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
   at org.jboss.web.tomcat.tc4.statistics.ContainerStatsValve.invoke(ContainerStatsValve.java:76)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
   at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2416)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
   at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
   at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:65)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
   at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:577)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
   at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
   at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:601)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392)
   at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)
   at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)
   at java.lang.Thread.run(Thread.java:536)
2004-03-02 08:57:16,456 WARN  [net.sf.hibernate.util.JDBCExceptionReporter] SQL Error: 1, SQLState: 23000
2004-03-02 08:57:16,456 ERROR [net.sf.hibernate.util.JDBCExceptionReporter] ORA-00001: unique constraint (DF_MT.XPKASSIGNED_DRIVER) violated

2004-03-02 08:57:16,456 WARN  [net.sf.hibernate.util.JDBCExceptionReporter] SQL Error: 1, SQLState: 23000
2004-03-02 08:57:16,456 ERROR [net.sf.hibernate.util.JDBCExceptionReporter] ORA-00001: unique constraint (DF_MT.XPKASSIGNED_DRIVER) violated

2004-03-02 08:57:16,456 DEBUG [net.sf.hibernate.impl.BatcherImpl] done closing: 0 open PreparedStatements, 0 open ResultSets
2004-03-02 08:57:16,456 DEBUG [net.sf.hibernate.impl.BatcherImpl] closing statement
2004-03-02 08:57:16,456 DEBUG [net.sf.hibernate.util.JDBCExceptionReporter] SQL Exception


Thanks for any help :)
// Mikael


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.