Hibernate Envers:用于选择在给定时间点有效的实体的AuditQuery
我使用Hibernate Envers和ValidityAuditStrategy。我想选择在给定时间点存在的实体的版本 我的修订信息在SQL中如下所示:Hibernate Envers:用于选择在给定时间点有效的实体的AuditQuery,hibernate,hibernate-envers,Hibernate,Hibernate Envers,我使用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
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)
);
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;
例如,用户希望查看给定实体的版本,有效期为2019-03-05 16:00:00
SQL必须如下所示:
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)
);
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;
AuditReader.getRevisionNumberForDate(java.util.Date)