1 Reply Latest reply: May 16, 2012 11:11 AM by Zakary Melvin RSS

How to access data returned by AuditQuery.getResultList();

Zakary Melvin Newbie

getResultList() returns a List<Object> containing all the data related to the audited entity.  Is there an easy to get to this data in the object. 

 

I get the data in the following way:

      AuditQuery query =getAuditReader(sessionFactory).createQuery().forRevisionsOfEntity(entityClass, false, true);

      query.add(AuditEntity.id().eq(id));

      query.add(AuditEntity.property(propertyName).hasChanged());

      List<Object> objList = query.getResultList();

 

 

I would like to traverse the objList to find the relevant audit data (field that changed and when)

 

Thanks for the help,

Zak

  • 1. Re: How to access data returned by AuditQuery.getResultList();
    Zakary Melvin Newbie

    okay...apparently the answer is to completely read the documentation.

     

    forRevisionsOfEntity

    public AuditQuery forRevisionsOfEntity(Class<?> c, String entityName, boolean selectEntitiesOnly, boolean selectDeletedEntities)
    Creates a query, which selects the revisions, at which the given entity was modified and with a given entityName. Unless an explicit projection is set, the result will be a list of three-element arrays, containing:
    1. the entity instance
    2. revision entity, corresponding to the revision at which the entity was modified. If no custom revision entity is used, this will be an instance of DefaultRevisionEntity
    3. type of the revision (an enum instance of class RevisionType)

     

    so the Array is returned and I need to do some casting to get the data I seek.

     

    List<Object> objList = query.getResultList();

    Object[] objArray = (Object[])objList.get(0);

    MyEntity myEntity = (MyEntity)objArray[0];

     

    with proper exception handling added of course.

     

    Zak