2 Replies Latest reply on Jun 12, 2008 2:23 PM by john hedden

    Entity Callback -- @PrePersist  vs. @PreUpdate

    john hedden Newbie

      I have the following in a SFSB:

      public void saveOrder() {
       try {
       if (order.getId() != null) {
       FacesUtil.addInfoMessage("Order Number: " + order.getOrderNumber() +" was successfully updated.");
       } else {
       FacesUtil.addInfoMessage("Your Order Number is: " + order.getOrderNumber());
       } catch (IllegalStateException se) {
       FacesUtil.addInfoMessage("Test ....");
       } catch (Exception e) {
       FacesUtil.addInfoMessage("Test2 ....");

      and this listener on the order object:
      public class OrderValidator {
       @PrePersist @PreUpdate
       public void validateSubmit(Order order) {
       if (order.getStatus() == Status.SUBMITTED) {
       if (order.getUploadFileList().size() < 1) {
       throw new IllegalStateException("Submitted orders must have at least one attachment.");

      When I try and get it to fail via persist, everything works fine and I get my FacesMessage. When I try and get it to fail via merge I get:
      [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator_2] TwoPhaseCoordinator.beforeCompletion - failed for com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple@6c43e2
      javax.persistence.PersistenceException: java.lang.IllegalStateException: Submitted orders must have at least one attachment.
       at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:527)

      and it never reaches either catch block in my SFSB. What gives?