1 Reply Latest reply on Sep 3, 2008 6:13 AM by loic

    Deadlock unmanaged

    loic

      I'm using SEAM with Ejb3 on jboss-4.0.5.GA, with SQL server 2000, driver jtds.
      On one of my server i got sometimes deadlock errors :


      2008-08-28 17:51:03,381 WARN [org.hibernate.util.JDBCExceptionReporter] SQL Error: 1205, SQLState: 40001
      2008-08-28 17:51:03,381 ERROR [org.hibernate.util.JDBCExceptionReporter] Transaction (Process ID 53) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
      2008-08-28 17:51:03,381 INFO [STDOUT] Exception during cancel org.hibernate.exception.LockAcquisitionException: could not execute query
      2008-08-28 17:51:03,381 ERROR [STDERR] javax.persistence.PersistenceException: org.hibernate.exception.LockAcquisitionException: could not execute query
      2008-08-28 17:51:03,381 ERROR [STDERR] at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:647)
      2008-08-28 17:51:03,381 ERROR [STDERR] at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:73)
      2008-08-28 17:51:03,381 ERROR [STDERR] at com.edieyes.optixml.ejb3.sessions.StockBean.cancel(StockBean.java:162)
      



      The most important matter is that after it (even if i catch the Exception) my next query are all failed.

      Here is my part of code failing (on about 1% of time) :
      @Stateless
      public class StockBean implements RemoteStock{
      @PersistenceContext(unitName = "stocktest")
       protected EntityManager em;
      
      
       public void cancel(String orderNumber, String jobNumber) {
       // TODO Auto-generated method stub
       try{
       String query="SELECT c FROM StockReserved as c where c.orderNumber=?1 and c.jobNumber=?2";
       Query q = em.createQuery(query).setParameter(1, orderNumber).setParameter(2,jobNumber);
      
       Iterator iterator =q.getResultList().iterator();
       while(iterator.hasNext()){
       StockReserved stockReserved=(StockReserved) iterator.next();
       String oldCodeArticle=stockReserved.getCodeArticle();
       int oldQuantite=stockReserved.getQuantite();
       int status=stockReserved.getStatus();
       Stock stock=(Stock) em.createQuery("SELECT c FROM Stock c where codeArticle = ?1").setParameter(1,oldCodeArticle).getSingleResult();
       if(status==0)stock.setStockPreReserved(stock.getStockPreReserved()-oldQuantite);
       else if(status==1)stock.setStockReserved(stock.getStockReserved()-oldQuantite);
      
       }
      
      
       query="delete FROM StockReserved as c where c.orderNumber=?1 and c.jobNumber=?2";
       q = em.createQuery(query).setParameter(1, orderNumber).setParameter(2,jobNumber);
       int deleted = q.executeUpdate();
       System.out.println(deleted+" JOBS DELETED ");
      
       /////*****IT FAILS HERE
      
       updateJobNumbers(orderNumber,jobNumber);
      
      
       }catch(Exception e){
      
       System.out.println("Exception during cancel "+e.getMessage());
      
      
       e.printStackTrace();
       }
       }
      
      }
      
      




      It's Called like that


      stockService.cancel("000021","001");
      



      The best should be not to have anymore this error... but all the tried I did failed.. so if you have a solution?

      Else I would like to have a way to go threw that and that the next query won't fail, because for now i have this Exception :


      javax.persistence.TransactionRequiredException: EntityManager must be access within a transaction
      2008-08-27 14:52:16,488 ERROR [STDERR] javax.ejb.EJBTransactionRolledbackException: javax.persistence.TransactionRequiredException: EntityManager must be access within a transaction
      2008-08-27 14:52:16,488 ERROR [STDERR] at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:93)
      

      or this one
      2008-08-28 17:51:03,490 WARN [org.hibernate.util.JDBCExceptionReporter] SQL Error: 0, SQLState: null
      2008-08-28 17:51:03,490 ERROR [org.hibernate.util.JDBCExceptionReporter] Transaction is not active: tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=SVR-EDIEYES/553168, BranchQual=, localId=553168]; - nested throwable: (javax.resource.ResourceException: Transaction is not active: tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=SVR-EDIEYES/553168, BranchQual=, localId=553168])
      2008-08-28 17:51:03,490 INFO [STDOUT] getSupplementsGridsPriceByFabArea org.hibernate.exception.GenericJDBCException: Cannot open connection
      



      THANKS FOR YOUR HELP