There's an unexpected behavior with composite keys mapped with @Id and Many-To-Many associations mapped as 2 Many-To-Ones.
I've create a test case:
Have a look at the entities: https://github.com/michael-simons/possible_hibernate_426_bug_with_date/tree/master/src/main/java/entities
A1 < AB1 > B1
and the same with "2".
Ax has a composite key that also references another Entity foobar which is - i hope - jpa conform. Please ignore that on MySQL the primary key is only defined as id, i wanted to use an auto-increment for id.
The only difference from the mappings is the naming of the id attribute in Ax.
In A1 it's called "id" and in A2 it's called "a2id".
When i run https://github.com/michael-simons/possible_hibernate_426_bug_with_date/blob/master/src/test/java/tests/IdColumnNamesTest.java the CriteriaQuery with a subquery (all Ax's that have a Bx) fails for the "1" entities with
"Caused by: java.sql.SQLException: Operand should contain 2 column(s)" on mysql and with
"SqlNode's text did not reference expected number of columns" on Oracle.
The A2 case where id has a different name works as expected (with the correct results in production).
This bug report does not indicate that the reported issue affects version 5.x. Versions prior to 5.x are no longer maintained. It would be a great help to the Hibernate team and community for someone to verify that the reported issue still affects version 5.x. If so, please add the 5.x version that you verified with to the list of affected-versions and attach the (preferably SSCCE) test case you used to do the verification to the report; from there the issues will be looked at during our triage meetings.
For details, see http://in.relation.to/2015/10/27/great-jira-cleanup-2015/
As part of verifying that this issue affects 5.0, please just set the "Affects version". Leave the "verify-affects-5.0" label and leave the issue in "Awaiting Response" status; these are critical for us to be able to track these verifications and triage them. Thanks.
I've set the appropriate versions for Hibernate 5 and added a standalone test case using an H2 database. The error is the same as running inside Oracle.
javax.persistence.PersistenceException: org.hibernate.HibernateException: SqlNode's text did not reference expected number of columns
when I'm expecting a simple query like
which Hibernate correctly generates when i rename the "id" attribute in "A" to whatever else.
I had a similar problem and found the Reason in class org.hibernate.hql.internal.ast.tree.BinaryLogicOperatorNode in hibernate-core-5.1.0.Final.jar.
In line 225: String splits = StringHelper.split( ", ", nodeText );
The split expression is comma blank, this means not comma followed by blank, but comma OR blank. Thus the splitting results in too many splits.
Removing the blank solves the problem of the "SqlNode's text did not reference expected number of columns" Exception.
I’m using this version:
and I’m facing the same issue. I’ve found a report of the same issue from 2010: https://forum.hibernate.org/viewtopic.php?f=1&t=1002518&sid=9b8566d17f6601311d0de83eff98d071. The conclusion is the same as @Martin Hönings’s comment above and the solution he proposed worked for me as well, i.e. removing space / changing ”, “ to ”,” in this line:
@Steve Ebersole is this something you guys are able to reproduce?