Hibernate Envers:查询修订版本时出现问题

发布于 2024-10-18 20:13:39 字数 2563 浏览 1 评论 0原文

我使用 Hibernate Envers 进行审计。我的实体看起来像这样:

@Entity
@Audited
public class Child
{
    @GeneratedValue
    @Id
    @Column
    private Long id;

    @Column
    private String test;

    // getters & setters
}

现在我想查询这样的修订:

query = reader.createQuery().forRevisionsOfEntity(Child.class, false, true);
query.add(AuditEntity.property("test").eq("child1"));

Long id = ...;
query = reader.createQuery().forRevisionsOfEntity(Child.class, false, true);
query.add(AuditEntity.property("id").eq(id));

第一个查询有效,执行第二个查询会抛出以下异常:

java.lang.ClassCastException: java.lang.Long cannot be cast to java.util.Map
    at org.hibernate.property.MapAccessor$MapGetter.get(MapAccessor.java:118)
    at org.hibernate.tuple.component.AbstractComponentTuplizer.getPropertyValue(AbstractComponentTuplizer.java:77)
    at org.hibernate.tuple.component.AbstractComponentTuplizer.getPropertyValues(AbstractComponentTuplizer.java:83)
    at org.hibernate.type.ComponentType.getPropertyValues(ComponentType.java:381)
    at org.hibernate.type.ComponentType.nullSafeGetValues(ComponentType.java:354)
    at org.hibernate.type.ComponentType.nullSafeSet(ComponentType.java:309)
    at org.hibernate.param.NamedParameterSpecification.bind(NamedParameterSpecification.java:67)
    at org.hibernate.loader.hql.QueryLoader.bindParameterValues(QueryLoader.java:567)
    at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1612)
    at org.hibernate.loader.Loader.doQuery(Loader.java:717)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:270)
    at org.hibernate.loader.Loader.doList(Loader.java:2294)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2172)
    at org.hibernate.loader.Loader.list(Loader.java:2167)
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:448)
    at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
    at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1258)
    at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
    at org.hibernate.envers.query.impl.AbstractAuditQuery.buildAndExecuteQuery(AbstractAuditQuery.java:95)
    at org.hibernate.envers.query.impl.RevisionsOfEntityQuery.list(RevisionsOfEntityQuery.java:104)
    at org.hibernate.envers.query.impl.AbstractAuditQuery.getResultList(AbstractAuditQuery.java:101)

我不知道为什么这会导致 ClassCastException。知道吗,我缺少什么?

I use Hibernate Envers for auditing. My entity looks like this:

@Entity
@Audited
public class Child
{
    @GeneratedValue
    @Id
    @Column
    private Long id;

    @Column
    private String test;

    // getters & setters
}

Now I would like to query revisions like this:

query = reader.createQuery().forRevisionsOfEntity(Child.class, false, true);
query.add(AuditEntity.property("test").eq("child1"));

Long id = ...;
query = reader.createQuery().forRevisionsOfEntity(Child.class, false, true);
query.add(AuditEntity.property("id").eq(id));

The first query works, executing the second throws the following exception:

java.lang.ClassCastException: java.lang.Long cannot be cast to java.util.Map
    at org.hibernate.property.MapAccessor$MapGetter.get(MapAccessor.java:118)
    at org.hibernate.tuple.component.AbstractComponentTuplizer.getPropertyValue(AbstractComponentTuplizer.java:77)
    at org.hibernate.tuple.component.AbstractComponentTuplizer.getPropertyValues(AbstractComponentTuplizer.java:83)
    at org.hibernate.type.ComponentType.getPropertyValues(ComponentType.java:381)
    at org.hibernate.type.ComponentType.nullSafeGetValues(ComponentType.java:354)
    at org.hibernate.type.ComponentType.nullSafeSet(ComponentType.java:309)
    at org.hibernate.param.NamedParameterSpecification.bind(NamedParameterSpecification.java:67)
    at org.hibernate.loader.hql.QueryLoader.bindParameterValues(QueryLoader.java:567)
    at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1612)
    at org.hibernate.loader.Loader.doQuery(Loader.java:717)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:270)
    at org.hibernate.loader.Loader.doList(Loader.java:2294)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2172)
    at org.hibernate.loader.Loader.list(Loader.java:2167)
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:448)
    at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
    at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1258)
    at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
    at org.hibernate.envers.query.impl.AbstractAuditQuery.buildAndExecuteQuery(AbstractAuditQuery.java:95)
    at org.hibernate.envers.query.impl.RevisionsOfEntityQuery.list(RevisionsOfEntityQuery.java:104)
    at org.hibernate.envers.query.impl.AbstractAuditQuery.getResultList(AbstractAuditQuery.java:101)

I have no clue why this leads to a ClassCastException. Any idea, what I'm missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

嘿咻 2024-10-25 20:13:40

比较两个审核实体的 ID 时,请使用 AuditEntity.id() 而不是 AuditEntity.property()

When comparing the ids of two audited entities, use AuditEntity.id() instead of AuditEntity.property().

忆梦 2024-10-25 20:13:40

_aud 表条目的 id 由实体的 id、REV 和 REVTYPE 组成,因此它是 3 个值的映射。最好的选择是使用 AuditEntity.id(),但 AuditEntity.property("id.id") 也可以

the id of an entry of a _aud table is made of the id of the entity, the REV, and the REVTYPE, so, its a map of 3 values. the best choice is using AuditEntity.id(), but AuditEntity.property("id.id") would also make it

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文