试图通过审计表上的自定义查询检索记录。我有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文档,但是我没有找到太多信息。有人可以帮我吗?
为了对审核表发出查询,您需要执行以下操作:
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();