1 Reply Latest reply on Jul 6, 2003 6:33 AM by adrian.brock

    Error in primary key generation

    parul_patidar

      Hello,
      I am using Postgresql database with jboss. I am using sequence block pattern for generating automatic primary key using source code provided by ejbdesignpattern book. but when i use transaction attribute of RequiresNew for method getValueAfterIncrementingBy I get following exception. excpetion disappear when transaction attribute is changed to Required but book recommends using RequiresNew attribute for the mehtod
      can sombody tell y this exception is being raised and workaround.
      15:57:23,507 WARN [TxCapsule] Transaction XidImpl [FormatId=257, GlobalId=c40//
      1, BranchQual=] timed out. status=STATUS_ACTIVE
      15:57:23,707 WARN [TxCapsule] Transaction XidImpl [FormatId=257, GlobalId=c40//
      2, BranchQual=] timed out. status=STATUS_ACTIVE
      15:57:23,707 WARN [BeanLock] wait() interrupted in txLock, possibly a timeout
      15:57:23,707 ERROR [BeanLock] Thread[RMI TCP Connection(2)-192.168.0.46,5,RMI Ru
      ntime]Saw rolled back tx=TransactionImpl:XidImpl [FormatId=257, GlobalId=c40//2,
      BranchQual=] waiting for txLock
      15:57:23,707 WARN [TxCapsule] Lock contention, tx=XidImpl [FormatId=257, Global
      Id=c40//2, BranchQual=]
      15:57:23,727 ERROR [LogInterceptor] RuntimeException:
      java.lang.RuntimeException: Transaction marked for rollback, possibly a timeout
      at org.jboss.ejb.plugins.lock.QueuedPessimisticEJBLock.waitForTx(QueuedP
      essimisticEJBLock.java:339)
      at org.jboss.ejb.plugins.lock.QueuedPessimisticEJBLock.doSchedule(Queued
      PessimisticEJBLock.java:211)
      at org.jboss.ejb.plugins.lock.QueuedPessimisticEJBLock.schedule(QueuedPe
      ssimisticEJBLock.java:159)
      at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockIntercep
      tor.java:103)
      at org.jboss.ejb.plugins.EntityCreationInterceptor.invoke(EntityCreation
      Interceptor.java:69)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInte
      rceptor.java:107)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxIntercep
      torCMT.java:291)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:9
      8)
      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.
      java:130)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:208)
      at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:493)
      at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker.invoke(BaseLoca
      lContainerInvoker.java:301)
      at org.jboss.ejb.plugins.local.EntityProxy.invoke(EntityProxy.java:38)
      at $Proxy34.getValueAfterIncrementingBy(Unknown Source)
      at com.gmi.mportal.SequenceSessionBean.getNextSequenceNumber(SequenceSes
      sionBean.java:62)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
      java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
      sorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)
      at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(S
      tatelessSessionContainer.java:660)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invo
      ke(CachedConnectionInterceptor.java:186)
      at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(Stat
      elessSessionInstanceInterceptor.java:77)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInte
      rceptor.java:107)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxIntercep
      torCMT.java:237)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:9
      8)
      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.
      java:130)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:208)
      at org.jboss.ejb.StatelessSessionContainer.invoke(StatelessSessionContai
      ner.java:313)
      at org.jboss.ejb.Container.invoke(Container.java:738)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:517)
      at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:
      383)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
      java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
      sorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)
      at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
      at sun.rmi.transport.Transport$1.run(Transport.java:148)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
      at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:4
      60)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport
      .java:701)
      at java.lang.Thread.run(Thread.java:536)
      15:57:23,747 ERROR [LogInterceptor] EJBException, causedBy:
      java.lang.RuntimeException: Transaction marked for rollback, possibly a timeout
      at org.jboss.ejb.plugins.lock.QueuedPessimisticEJBLock.waitForTx(QueuedP
      essimisticEJBLock.java:339)
      at org.jboss.ejb.plugins.lock.QueuedPessimisticEJBLock.doSchedule(Queued
      PessimisticEJBLock.java:211)
      at org.jboss.ejb.plugins.lock.QueuedPessimisticEJBLock.schedule(QueuedPe
      ssimisticEJBLock.java:159)
      at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockIntercep
      tor.java:103)
      at org.jboss.ejb.plugins.EntityCreationInterceptor.invoke(EntityCreation
      Interceptor.java:69)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInte
      rceptor.java:107)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxIntercep
      torCMT.java:291)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:9
      8)
      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.
      java:130)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:208)
      at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:493)
      at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker.invoke(BaseLoca
      lContainerInvoker.java:301)
      at org.jboss.ejb.plugins.local.EntityProxy.invoke(EntityProxy.java:38)
      at $Proxy34.getValueAfterIncrementingBy(Unknown Source)
      at com.gmi.mportal.SequenceSessionBean.getNextSequenceNumber(SequenceSes
      sionBean.java:62)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
      java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
      sorImpl.java:25)

        • 1. Re: Error in primary key generation

          You probably have the bean already locked in the
          previous transaction.

          TX1 access bean with key X
          TX2 try to access bean with key X
          (waits for TX1 to finish which it cannot do, it is
          on the same thread)

          Using Required will mean they both run in the same
          TX1, but it will remain locked until you commit the
          transaction.

          Regards,
          Adrian