5 Replies Latest reply on May 16, 2007 11:34 PM by tarciosaraiva

    merge() behavior - is that correct?

    tarciosaraiva

      Hi there,
      I'm new to EJB3 and not sure if the behavior is correct or not.

      I have a stateless session bean that searches for an Entity bean and returns the found object to the client:

      FIRST SESSION BEAN
      
      public DestructionBin findDestructionBin(long id) {
       return manager.find(DestructionBin.class, id);
      }
      


      The client is a struts application. The returned entity is assigned to an ActionForm and is then changed on a webpage. Once the form is submitted I get this modified entity and call an update method on another stateless session bean.

      STRUTS ACTION PROCESSING...
      
      public ActionForward saveData(ActionMapping mapping, ActionForm form,
       HttpServletRequest request, HttpServletResponse response) {
       EditBinForm formObj = (EditBinForm) form;
      
       try {
       ManageDestructionBin mngBins = (ManageDestructionBin) GeneralWebUtil.getJNDIObject(ManageDestructionBinBean.JNDILocal, ManageDestructionBin.class);
      
       if (formObj.getId() > 0)
       mngBins.updateDestructionBin(formObj.getBin(), formObj
       .getWarehouse());
      ...
      
      SECOND SESSION BEAN
      
      public boolean updateDestructionBin(DestructionBin bin, long warehouse)
       throws WarehouseException {
       try {
       Warehouse wh = mngWarehouse.findWarehouse(warehouse);
       bin.setWarehouse(wh);
       manager.merge(bin);
       } catch (Exception e) {
       throw new WarehouseException(e.getMessage());
       }
      
       return true;
      }
      


      However, when the merge is called.. this is the stacktrace I get from EJB server:

      09:43:51,941 WARN [JDBCExceptionReporter] SQL Error: 0, SQLState: null
      09:43:51,941 ERROR [JDBCExceptionReporter] Batch entry 0 update TBL_DESTRUCTION_BIN set LASTUPDATE_=2007-05-16 09:43:51.809000 +1000, STATUS_=NULL, CLIENTREF_=VIC71234560, ACCESSCOUNT_=0, CREATEDBY_=NULL, BARCODE_=NULL, CREATEDATE_=NULL, LASTACCESSED_=NULL, PRINTED_=0, TYPE_=ST, SIZE_=1L, WAREHOUSE_=2, DEPARTMENT_=NULL, BUSINESSDAY_=0, COLLECTIONDATE_=NULL, DELIVERYDATE_=NULL, ROTATIONSCHEDULE_=NULL where ID_=4 was aborted. Call getNextException to see the cause.
      09:43:51,942 WARN [JDBCExceptionReporter] SQL Error: 0, SQLState: 23502
      09:43:51,942 ERROR [JDBCExceptionReporter] ERROR: null value in column "status_" violates not-null constraint
      09:43:51,942 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
      org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
      


      Could anyone please tell me if this is the correct behavior? It's quite annoying to find the object again and just change the updated fields.. and I also don't think this is the solution for it ehehehehe