• I added @Audited in my entities;
  • I created my listener to add the user ID to revinfo;
  • I can filter audited data with user id, entity class, min and max date, using:

    public <T extends BaseModel> List<Object[]> buscar(Class<T> clazz, Usuario usuario, java.util.Date inicio, java.util.Date fim){
    GregorianCalendar novo = new GregorianCalendar();
    novo.setTime(fim);
    novo.add(Calendar.DAY_OF_MONTH, 1);
    
    AuditReader reader = AuditReaderFactory.get(getEm());
    return reader.createQuery()
        .forRevisionsOfEntity(clazz, false, true)
        .add(AuditEntity.revisionProperty("usuario")
            .eq(usuario))
        .add(AuditEntity.revisionProperty("revtstmp")
            .between(inicio.getTime(), novo.getTime().getTime()))
        .addOrder(AuditEntity.property("id")
            .asc())
        .getResultList();
    
    }
    

But all relationships are lazy, including the @ManyToOne.

I found many post about problems with @OneToMany, but this is not the case

What can I do to access these properties?

PS: I tried, but could not highlight the code.

有帮助吗?

解决方案

All relations in the objects returned by Envers are lazy, regardless if it's a one-to-many or many-to-one.

In an object, to access the related object's properties just call the getter :)

In a query, it's not possible. Joins are not supported, also regardless of the relation type. You can only constraint the id of the related entity, but not its properties.

其他提示

From version 4.x in hibernate-envers you do not need to configure the listeners. you can easily audit an entity with @Audited.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top