Hibernate Envers:AuditQuery用于选择在给定时间点有效的实体

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

我使用带有ValidityAuditStrategy的Hibernate Envers。我想选择一个实体的版本,因为它在给定的时间点存在。

我的修订信息在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(???, ???))
hibernate hibernate-envers
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.