Column not found (wrong table name)

Description

Since 5.4.13 and all the way to 5.4.25 hql is converted to SQL with a mistake. A column in a nested statement is prefixed with the wrong table name and that gives a "Column not found" error (com.microsoft.sqlserver.jdbc.SQLServerException).
The problem seems to be that converting the function size() generates bad SQL.
I have the following condition in HQL: size(course.schedule.activities) = 0
In 5.4.12 (and previously) the SQL being generated was
(select count(activity4_.Schedule_ID) from Activity activity4_
where schedule1_.ScheduleID=activity4_.Schedule_ID)=0
But starting with 5.4.13 the SQL is
(select count(activity4_.Schedule_ID) from Activity activity4_
where course0_.ScheduleID = activity4_.Schedule_ID)=0
The mistake is that the column ScheduleID is now prefixed with the wrong table alias (course0_ instead of schedule1_). Both tables exist in the outer FROM-clause (where there is a cross join), but somehow the column reference gets wrong in the nested statement.

Environment

Java 8, tomcat 9 on ubuntu, sql server (jdbc driver 8.4.1.jre8)

Activity

Show:
Nikos Dimitrakas
December 3, 2020, 11:24 AM
Edited

I am guessing this broke because of . And now I see that you started working on which seems to be the same problem.

Andrea Boriero
December 3, 2020, 11:52 AM

I know what caused the issue and that can be a similar problem but the test provided by the reporter and that will be used to check the fix may not cover your specific case. For this reason I asked you a test case.

Nikos Dimitrakas
December 3, 2020, 12:21 PM

I am not really that familiar with how to create test cases. I looked at the test case from and the only thing that I don’t see is the column names. In my case the columns don’t have the same name in the two tables. I use xml-mappings, not annotations. Maybe you can modify the existing test case (or create a copy) with different column names so that Student has its own studentID and a foreign key to Teacher called teacher_ID and the Teacher has a teacherID. The Skill could have a foreign key to Teacher called owner_ID. That would make the Skill not reusable for multiple Teachers. Thus all columns would have different names and you can avoid having the code work by chance.

Andrea Boriero
December 3, 2020, 12:37 PM

I’ll try to follow you indication, by the way here you can find a project that helps creating test cases https://github.com/hibernate/hibernate-test-case-templates/ you can use

Andrea Boriero
December 4, 2020, 10:24 AM

Hi ,

I'm closing this Jira as a duplicate of https://hibernate.atlassian.net/browse/HHH-13944.

Thanks for reporting it.

Duplicate

Assignee

Unassigned

Reporter

Nikos Dimitrakas

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Worked in

5.4.12

Affects versions

Priority

Major
Configure