3 Replies Latest reply on Jun 27, 2011 11:09 AM by adamw

    Deleted entities when querying for entities at revision

    anonimo

      Hi,

       

      At the moment I am trying to retrieve the list of entities that changed between two specific dates. This should include modifed and deleted entities, returning only the most recent revision within that timeframe.

       

      The only possible way seems to be:

       

      //Find out the revision of the end date

      Number revision = reader.getRevisionNumberForDate(endDate);

       

      query = reader

             .createQuery()

             .forEntitiesAtRevision(PricingConfig.class, revision)

             .add(AuditEntity.revisionProperty("timestamp").ge(startDate));


      However, if an entity was modified and then deleted within that timeframe, that entity is not returned. It only seems to work for modified entities, but not for deleted ones. Is there any specific reason for this behavior? Any alternatives that return also deleted entities?

        • 1. Re: Deleted entities when querying for entities at revision
          adamw

          I think you should rather use the revisions-of-entity query.

          First you get the bounding revisions:

           

          Number startRevision = reader.getRevisionNumberForDate(startDate);

          Number enRevision = reader.getRevisionNumberForDate(endDate);

           

          Then you do the query:

           

          reader.createQuery.forRevisionsOfEntity(PC.class, true, true)

             .add(AuditEntity.revisionNumber().ge(startRevision)

             .add(AuditEntity.revisionNumber().le(endRevision));

           

          Adam

          • 2. Re: Deleted entities when querying for entities at revision
            slominskir

            I would also like to just query for a specific revision of an entity, and include deleted ones.  I have a method that takes an entity Id and revision Id and uses the forEntitiesAtRevision query.  It appears to work for all cases except when the revision represents a delete.  In that case I get a javax.persistence.NoResultException and upon inspection of the SQL that is generated I see that there is a where REVTYPE<>2  condition.  Why is this condition present?  Is this a bug?

             

            The workaround of using forRevisionsOfEntity does work though.

            • 3. Re: Deleted entities when querying for entities at revision
              adamw

              Yes, well, maybe not really a bug, just the API lacks the possibility to create an appropriate query. So rather an overlooked feature


              Adam