我将Hibernate Envers与ValidityAuditStrategy一起使用。我想选择在给定时间点存在的实体版本。
我的修订信息在SQL中如下所示:
create table revinfo (
rev int,
revtstmp datetime2,
primary key(rev)
);
我的审计实体如下:
create table products_aud (
id long,
name varchar(255),
rev int, -- this is a foreign key into revinfo
revend int, -- this is a foreign key into revinfo
revtype smallint,
primary key(id, rev)
);
例如,用户想要查看给定实体的版本,该版本的有效期为2019-03-05 16:00:00。
SQL必须看起来像这样:
select * from (
select id, name, revtype, x.rev, revend, revtstmp
from products_aud x join revinfo y
on x.rev = y.rev
where id = 14 and y.revtstmp <= '2019-03-05 16:00:00'
) as a
join (
select id, name, revtype, x.rev, revend, revtstmp
from products_aud x left outer join revinfo y
on x.revend = y.rev
where id = 14 and (y.revtstmp >= '2019-03-05 16:00:00' or x.revend is null)
) as b
on a.rev = b.rev;
AuditQuery的外观如何?我对AuditProperty::leProperty(otherAlias, otherPropertyName)
的otherAlias参数感到困惑。
到目前为止,我知道了:
AuditQuery auditQuery = queryCreator.forRevisionsOfEntity(Product.class, true, true);
auditQuery.add(AuditEntity.revisionProperty("revtstmp").leProperty(???, ???))
答案 0 :(得分:1)
AuditReader.getRevisionNumberForDate(java.util.Date date)