9 Replies Latest reply on Oct 31, 2011 11:07 AM by Adam Warski

    Retrieving full revision hierarchy of entity

    Paul de Raaij Newbie

      Hello,

       

      Perhaps I am expecting too much of Envers, but I have a problem we can't get the grasp of it. We have a pretty extensive domain model which is audited by Envers. The root entity is Form which contains a map of FormElements. Each FormElement has a couple of relations, for now I just show one. This is a relation to FormElementValidationRuleConfiguration.

       

      I have a Service class which retrieves a Form of a particular revision. This form instance contains all the elements (FormElement) belonging to the Form. All the relations of FormElement are empty or they are initialized but with null values. While I'd expect that it contains alle the configuration belonging to that formelement for the particular revision.

       

      I hope i've made my problem domain clear and that someone could help me with this challenge. We are using hibernate 3.5.6 and unfortunately it isn't possible to upgrade at the moment to a newer release.

       

      Entity: form

      {code}

           @Audited

          @Entity(name = "Form")

          @DisplayProperty(displayProperty1 = "name")

          public class Form extends IdentityIdEntity<Integer> {

       

                  @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)

                    @MapKey(name = "id")

                    private Map<Integer, FormElement> elements = new HashMap<Integer, FormElement>();

       

          }

      {/code}

       

      Entity: FormElement

       

      {code}

          @Audited

          @Entity(name = "FormElement")

          @Inheritance(strategy = InheritanceType.JOINED)

          @DisplayProperty(displayProperty1 = "name")

          public abstract class FormElement extends TranslatableIdentityIdEntity<Integer, FormElementTranslation> implements

                              Comparable<FormElement> {

       

                  @Column(length = 50, nullable = false)

                    private String name;

       

                

                 @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)

                 private Map<FormElementValidationRuleType, FormElementValidationRuleConfiguration> validations = new HashMap<FormElementValidationRuleType, FormElementValidationRuleConfiguration>();

       

       

          }

      {/code}

       

      Entity: FormElementValidationRuleConfiguration

       

      {code}

      @Audited

      @Entity

      @DisplayProperty(displayProperty1 = "validationRule")

      public class FormElementValidationRuleConfiguration extends IdentityIdEntity<Integer> {

          

        @ManyToOne(fetch = FetchType.EAGER, optional = true)

                @NotAudited

                private FormElementValidationRule validationRule;

       

       

                private String expression;

       

       

                private String errorMessage;

       

      }

      {/code}

       

      Service: FormVersioningService

       

      {code}

      public Form findFormByIdAndRevision(int revisionNumber, int formId) {

                          AuditReader auditReader = AuditReaderFactory.get(sessionFactory.getCurrentSession());

       

                          Form versionedForm = auditReader.find(Form.class, formId, revisionNumber);

       

                          return versionedForm;

                }

      {/code}