gpt4 book ai didi

java - Hibernate 谓词 - 无效路径

转载 作者:行者123 更新时间:2023-12-02 11:11:52 27 4
gpt4 key购买 nike

让我们拥有三个实体:Event、MessageEvent 和 Message。 MessageEvent 是 Event 的子类(具有正确设置的 DiscriminatorValue)。 MessageEvent 还有一个附加属性“message”,其类型为 Message。其定义如下:

@ManyToOne(optional = false, cascade = CascadeType.REMOVE)
@JoinColumn(name = "MESAGE_ID", nullable = false)
private Message message;

现在,我们尝试设置一个谓词来查找消息 id 为 2 的所有 MessageEvent-s。我们按以下方式执行此操作:

cb.equal(cb.treat(root, MessageEvent.class).join(MessageEvent_.message, JoinType.LEFT).get(Message_.id), 2)

代码编译得很好,但是,我们在运行时收到此错误:

5:40:59,891 ERROR [org.hibernate.hql.internal.ast.ErrorCounter] (default task-2)  Invalid path: 'generatedAlias1.id':  Invalid path: 'generatedAlias1.id'
at org.hibernate//org.hibernate.hql.internal.ast.util.LiteralProcessor.lookupConstant(LiteralProcessor.java:114)
at org.hibernate//org.hibernate.hql.internal.ast.tree.DotNode.resolve(DotNode.java:214)
at org.hibernate//org.hibernate.hql.internal.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:109)
at org.hibernate//org.hibernate.hql.internal.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:104)
at org.hibernate//org.hibernate.hql.internal.ast.HqlSqlWalker.resolve(HqlSqlWalker.java:1033)
at org.hibernate//org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1286)
at org.hibernate//org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4699)
at org.hibernate//org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:4169)
at org.hibernate//org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2134)
at org.hibernate//org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2084)
at org.hibernate//org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2084)
at org.hibernate//org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2084)
at org.hibernate//org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2084)
at org.hibernate//org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2059)
at org.hibernate//org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2059)
at org.hibernate//org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:813)
at org.hibernate//org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:607)
at org.hibernate//org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:311)
at org.hibernate//org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:259)

Hibernate 显然在构建相应的 SQL 查询时存在问题。问题出在 Hibernate 本身还是我们做错了什么?

可在 https://github.com/JurajMlich/hibernate-bug-demonstration 获取最小演示。 。

在 Java 8、Java 10 (openjdk)、Wildfly 10、Wildfly 12 上进行测试。使用 eclipse link ORM 时可以正确处理相同的查询。

最佳答案

问题出在 Hibernate 的背后。我什至在他们的错误跟踪系统中发现了该错误,并发现它已经被修复 - https://hibernate.atlassian.net/browse/HHH-10561 。然而,Wildfly 12 使用 5.1.x 。将Hibernate升级到5.2.17后,问题消失。

关于java - Hibernate 谓词 - 无效路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50562585/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com