5 Replies Latest reply: Oct 19, 2011 2:41 AM by Paul de Raaij RSS

    Get revision numbers of root entity and their entities in collections

    Paul de Raaij Newbie

      At the moment I am experimenting with the envers library in our application for integration. Whenever I do an getRevisions I only get the revisions for the root entity.

       

      However I expect Envers to be able to get the revisions for the entities in the enclosed collections as well. I tried some custom queries but aren't able to combine the two together via a join or something else.

       

       

      The entities are as follow:

       

       

      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;

       

          }

      {/code}

       

      Service: FormVersioningService

      {code}

          public List<Number> findVersionsOfForm(Form form) {

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

       

                              logger.info(auditReader.getRevisions(Form.class, form.getId()).toString());

       

                              List resultList = auditReader.createQuery().forRevisionsOfEntity(FormElement.class, false, true)

                                                  .addProjection(AuditEntity.revisionNumber()).add(AuditEntity.property("form_id").eq(form.getId()))

                                                  .getResultList();

                              logger.info(resultList);

       

                              return null;

       

                    }

      {/code}

       

      The first log returns:

       

      {quote}

      > INFO: [16, 19, 20, 24]

      {/quote}

       

      The second returns:

       

      {quote}

      > INFO: [24, 25]

        {/quote}

       

      But I'd like to get the following result:

       

      {quote}

      > INFO: [16, 19, 20, 24, 25]

      {/quote}

       

      I'm using Hibernate 3.5.6 and at the moment it isn't possible to upgrade to a new version, so I'm searching for a solution within this version.

       

       

      Any help is welcome and will be appreciated

       

      Original post on Stack Overflow: http://stackoverflow.com/questions/7688430/get-revision-numbers-of-root-entity-and-their-entities-in-collections