"Automatic" merging of a selection of nested objects occurs after updating Hibernate

After switching to a new version of sleep mode (suppose that this happened with the switch from JBoss 4.2.2 to JBoss 6), some requests do not work 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 always happens when using this query:

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

The solution to this problem is to give "entityA.entityB" an alias, and then use that alias in the WHERE . But in some queries, the LEFT JOIN FETCH is not explicitly set, but still the WHERE uses the property of the reference object. Is it really not possible? What has changed, so that he unexpectedly crashed after switching to a new version of JBoss?

The next question is related to this question and includes a solution, but does not explain the problem.

+6
source share
2 answers

The request must be

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

those. you should assign an alias to each merged object and use this alias for subsequent joins or restrictions.

+3
source

I have the same problem in my project, and it is very difficult to solve, because I have a large legacy system with a lot of modules that use pre-compiled named queries and many queries created on demand. To identify and modify the entire system and make changes where it worked using the outdated version of hibernate, this is a very annoying job and error prone. I consider this problem in JBoss from 6.4 to 6.4.6 when the sleep mode version was updated from 4.2.18 to 4.2.22 and this error appears. To solve this problem, I only downgrade the main sleep module to the original version 4.2.18 by default, but this is not good, because when the next JBoss patch arrives, I need to change it again. I am trying to use JBoss modules and some configuration in persistence.xml and jboss-deployment-strcuture.xml, but have failed so far.

0
source

Source: https://habr.com/ru/post/892318/


All Articles