如何在审核表休眠envers上运行自定义查询

问题描述 投票:0回答:1

试图通过审计表上的自定义查询检索记录。我有Hibernate实体结构,如下所示。.,

@Audited
@Entity
public class TableA {
    @EmbeddedId
    private PrimaryKeyID primaryKeyID;
    private Double price;
    private Date modifiedOn;
    private String status;
}
@Embeddable
public class PrimaryKeyID implements Serializable {
    private Integer Id;
}

我试图通过AuditFactory复制的查询是

SELECT * FROM table_A_aud where id = ? and status=? order by modifiedOn desc limit 3;

Envers上的Tried Hibernate文档,但是我没有找到太多信息。有人可以帮我吗?

spring-data-jpa hibernate-envers
1个回答
0
投票

为了对审核表发出查询,您需要执行以下操作:

List results = AuditReaderFactory.get( session )
  .createQuery()
  .forRevisionsOfEntity( TableA.class, true, false )
  .add( AuditEntity.id().eq( entityId ) )
  .add( AuditEntity.property( "status" ).eq( entityStatus ) )
  .addOrder( AuditEntity.property( "modifiedOn" ).desc() )
  .setMaxResults( 3 )
  .getResultList();
© www.soinside.com 2019 - 2024. All rights reserved.