1 Reply Latest reply on Jul 9, 2010 2:43 AM by Syed Mahdi

    Audit reader Query help needed

    Syed Mahdi Apprentice

      Hi All,

       

       

      I am working with hibernate 3.5.3 and  Envers that comes with it. I am trying to make auditreader querries to coem up with results:
      My RevisionEntity is customized and looks like this:

      @RevisionEntity(LossShareEnversListener.class)
      public class LossShareRevisionEntity  {
       
      @RevisionNumber
          private int id;
          @RevisionTimestamp
          private long timestamp;
           private String username;
      private String screenName;
      /*getters setters follow for each*/

      How can i get to make a query where I can list all the revisions made by a certain username,
      when i use

       

      AuditQuery queryForEntities = auditreader.createQuery().forEntitiesAtRevision(MyEntity, revisionNumber);
        queryForEntities.add(AuditEntity.property("username").eq("admin"));

       

      It searches for username in the Audited Entity like Customer_aud so ofcourse it is going to throw exception as there is no column username in Customer table. I tried to find something like "AuditEntity" in the same package but i couldnt find RevisionEntity to replace the part in  queryForEntities.add().
      So how can I list all the revisions on the basis of username in _revision_info/revinfo table. It should be the same way if someone wants to find revision on the basis of timestamp but i didnt find any examples for that either or that would ahve helped.
      Any help will be appreciated.
      thanks.
      Syed

       

      Message was edited by: Syed Mahdi

        • 1. Re: Audit reader Query help needed
          Syed Mahdi Apprentice

          for anyone out there needing help:

           

           

          reader.createQuery().forRevisionsOfEntity(entity, false, true)
          .addOrder(AuditEntity.revisionProperty("timestamp").asc())
          .add(AuditEntity.revisionProperty("username").eq(userName))
          .add(AuditEntity.revisionProperty("timestamp").ge(timestamp.getTime())).getResultList();