Aggregate on (mappedBy) joined column produces invalid query

Description

We came across the following JQL query (which admittedly is not very useful as usedBy is actually mappedBy=uses - but I guess this can be reproduced with more useful ones) which starting with some changes in 5.2.3-5.2.4 (cannot really test 5.2.3 as this is broken for another reason) produces an query that derby considers invalid, although I'm not exactly sure why - Derby bug? The trigger seems to be that the inverse relation join now is replaced by a subquery.

JQL query:

Resulting query:

Results in SQLSytaxErrorException:
Column 'ABSTRACTCO4_.ID' is either not in any table in the FROM list or appears within a join specification and is outside the scope of the join specification or appears in a HAVING clause and is not in the GROUP BY list. If this is a CREATE or ALTER TABLE statement then 'ABSTRACTCO4_.ID' is not a column in the target table.

Query in 5.2.2:

Environment

Apache Derby 10.13.1.1 (10.12.1.1 also)

Activity

Show:
Christian Beikov
November 7, 2016, 12:29 PM

You can disable the subquery rewriting behavior in 5.2.4 now with the property hibernate.collection_join_subquery. Also see https://docs.jboss.org/hibernate/orm/current/userguide/html_single/Hibernate_User_Guide.html#configurations-misc

Could you maybe also share the entity model so I can understand what is happening there?

Moritz Bechler
November 7, 2016, 1:03 PM

Will try with the property disabled, thanks.

The model unfortunately is pretty huge, but for the parts I guess might be relevant:

Christian Beikov
November 8, 2016, 7:55 AM

I am able to reproduce it, investigating now.

Christian Beikov
November 8, 2016, 8:23 AM

Feeling a bit embarrased. I had extra spaces in the regex pattern which was fine for the case when using the operator like but not any other operator since the spaces there are omitted. The fix in the PR should solve your issue: https://github.com/hibernate/hibernate-orm/pull/1615

Gail Badner
June 8, 2017, 12:25 AM

Fixed in 5.1 as well.

Assignee

Christian Beikov

Reporter

Moritz Bechler

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure