7 Replies Latest reply on Aug 27, 2009 9:42 PM by schamarthi

    Are Transient Fields empty in @PreUpdate functions?

    mvkessel

      My class 'EEntity' has a transient field 'entityType' which
      is required by function 'EEntity.updatePropertiesAndFields()'.
      This function is called before persisting or updating an EEntity object.

      This works fine for a 'PrePersist' operation. However when changing
      the object in the GUI and performing a 'merge' the transient field
      'entityType' has lost its value.

      (see source code)
      I check in the session-bean before calling 'em.merge', the type is 'Purchase Order':

      2006-01-30 00:53:16,000 INFO [STDOUT] 30-Jan-2006 00:53:16 common.util.ELogger debug
      SEVERE: mergeEntity: entityType is :Purchase Order

      I check in the @PreUpdate function and the type is empty:

      2006-01-30 00:53:16,031 INFO [STDOUT] 30-Jan-2006 00:53:16 common.util.ELogger severe

      SEVERE: updateProperties: entityType is empty: 17401-110


      Am I missing something or are all transient fields empty in @PreUpdate functions ???


      Any help would be well appreciated,

      Marc



      @Stateless
      @TransactionAttribute(TransactionAttributeType.REQUIRED)
      public class EInstanceManagerBean implements EInstanceManager, EInstanceManagerRemote, Serializable {

      @PersistenceContext(unitName = "ngerp")
      protected EntityManager em;
      ...

      public void mergeEntity(EEntity entity) {


      if(entity.getEntityType()==null){
      ELogger.severe("mergeEntity: entityType is empty"+entity.getDescription());
      } else {
      ELogger.debug("mergeEntity: entityType is :" +entity.getEntityType().getDescription());
      }

      em.merge(entity);
      }
      ...
      }



      @Entity(access = AccessType.FIELD)
      @Inheritance(strategy = InheritanceType.SINGLE_TABLE, discriminatorType = DiscriminatorType.STRING, discriminatorValue = "E")
      public class EEntity implements Serializable

      ...
      @Transient
      private EEntityType entityType;

      ...

      @PrePersist
      @PreUpdate
      private void updatePropertiesAndFields()
      {
      if(this.getEntityType()==null){
      ELogger.severe("updateProperties: entityType is empty: "+this.getDescription());
      } else {
      ELogger.debug("updateProperties: entityType is: " +this.getEntityType().getDescription());
      }

      EInstanceHelper.updateEntityFields(this);
      this.setPropertiesXml(PropertiesXml.convertPropertiesToXml(this.properties));
      }