0 Replies Latest reply on Jun 8, 2006 8:56 PM by simon wang

    em.persist(Object) error  in multiple-thread environment

    simon wang Newbie

      Deal All:
      I have a sesseion bean like this:
      public @Stateless class InventoryMgrBean implements InventoryMgrLocal,InventoryMgrRemote {
      private static Object lock=new Object();
      --------------------------------
      public NEKey findByNEPK(NEPK nePK) {
      NEKey neKey=null;
      try{
      Query q=em.createQuery("select n from NEKey n where n.wwn=:WWN");
      q.setParameter("WWN",nePK._wwn);
      neKey=(NEKey)q.getSingleResult();
      }catch(NoResultException e){
      return null;
      }
      return neKey;
      }
      -----------------------------
      public NEKey createNEKey(NEPK nePK) {
      try {
      synchronized (lock) {
      NEKey neKey = findByNEPK(nePK);
      if (neKey == null) {
      neKey = new NEKey();
      neKey.setWwn(nePK.get_wwn());
      neKey.setIpAddresses(nePK.get_ipAddresses());
      neKey.setName(nePK.get_name());
      em.persist(neKey);
      }
      return neKey;
      }
      } catch (Exception e) {
      e.printStackTrace();
      return null;
      }

      }
      When multiple-thread try to invoke this createNEKey() method.Exception(JDBC batch update fail) will be thrown at em.persist(neKey).Class NEKey is entity bean with ID auto-generated.
      Can anyone give some advice?
      Great Thanks!
      Kingofhawks