“自动”更新 Hibernate 后,联合获取嵌套实体失败

发布于 2024-11-19 05:41:28 字数 898 浏览 4 评论 0原文

升级到较新的 hibernate 版本后(猜测是从 JBoss 4.2.2 切换到 JBoss 6 时出现的),某些查询失败并显示消息:

引起原因:java.lang.IllegalArgumentException:org.hibernate.QueryException:查询指定连接获取,但获取的关联的所有者不存在于选择列表中[FromElement {显式,不是集合连接,获取连接,获取非-惰性属性,classAlias=null,role=null,tableName= (...)

使用这样的查询时总是出现这种情况:

SELECT entityA FROM EntityA entityA 
JOIN FETCH entityA.entityB
LEFT JOIN FETCH entityA.entityB.someField
WHERE entityA.entityB.anotherField LIKE :someParameter

问题的解决方案是给出“entityA.entityB”一个别名,然后在 WHERE 子句中使用此别名。但在某些查询中,LEFT JOIN FETCH 未明确给出,但 WHERE 子句仍然使用引用实体的属性。那里也会失败吗?到底发生了什么变化,以至于切换到新的 JBoss 版本后突然失效了?

以下问题 与这个问题相关并包含解决方案,但没有解释问题。

After upgrading to a newer hibernate version (guess it came with the switch from JBoss 4.2.2 to JBoss 6), some queries fail with the message:


Caused by: java.lang.IllegalArgumentException: org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list [FromElement{explicit,not a collection join,fetch join,fetch non-lazy properties,classAlias=null,role=null,tableName= (...)

This is always the case when using a query like this:

SELECT entityA FROM EntityA entityA 
JOIN FETCH entityA.entityB
LEFT JOIN FETCH entityA.entityB.someField
WHERE entityA.entityB.anotherField LIKE :someParameter

The solution to the problem is to give "entityA.entityB" an alias and then to use this alias in the WHERE clause. But in some queries the LEFT JOIN FETCH is not explicitely given but still the WHERE clause uses the property of a referenced entity. Will it also fail there? What has changed, so that it suddenly fails after switching to a new JBoss version?

The following question is related to this question and includes the solution, but doesn't explain the problem.

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

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

发布评论

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

评论(2

夜未央樱花落 2024-11-26 05:41:28

查询应该是

SELECT entityA FROM EntityA entityA 
JOIN FETCH entityA.entityB entityB
LEFT JOIN FETCH entityB.someField
WHERE entityB.anotherField LIKE :someParameter

I.e.您应该为每个连接实体分配一个别名,并使用此别名进行后续连接或限制。

The query should be

SELECT entityA FROM EntityA entityA 
JOIN FETCH entityA.entityB entityB
LEFT JOIN FETCH entityB.someField
WHERE entityB.anotherField LIKE :someParameter

I.e. you should assign an alias to each joined entity, and use this alias for subsequent joins or restrictions.

懒猫 2024-11-26 05:41:28

我在我的项目中遇到了同样的问题,并且很难解决,因为我有一个大型遗留系统,其中有很多模块使用预编译的命名查询和大量按需创建的查询。使用旧版本的 hibernate 来识别和修改整个系统并更改正在运行的位置是一项非常烦人的工作并且容易出错。
当 hibernate 版本从 4.2.18 升级到 4.2.22 时,我在 JBoss 从 6.4 到 6.4.6 中遇到了这个问题,并且出现了这个错误。为了解决这个问题,我只将 hibernate 主模块降级到初始默认版本 4.2.18,但这并不好,因为当 JBoss 的下一个补丁到达时,我需要再次更改它。我正在尝试使用 JBoss 模块以及 persistence.xml 和 jboss-deployment-strcuture.xml 中的一些配置,但尚未成功。

I have the same trouble in my project and it´s very hard to solve because I have a large legacy system with a lot of modules that use pre-compiled namedqueries and a lot of queries created on demand. To identify and modify the whole system and make changes where was working as well using a old version of hibernate is a very annoying work and error prone.
I'm going through this problem in JBoss from 6.4 to 6.4.6 when hibernate version was upgrade from 4.2.18 to 4.2.22 and this error appear. To solve it I make a downgrade of only hibernate main module to initial default version 4.2.18 but this is not good because when the next patch of JBoss arrive I need to change it again. I´m trying use the JBoss modules and some configuration in persistence.xml and jboss-deployment-strcuture.xml but without success yet.

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