criteria-api: filtering by key-many-to-one causes invalid sql
Description
Attachments
causes
is duplicated by
Activity

Guram SavinovMay 9, 2013 at 4:06 PM
You can get test case project from: https://github.com/savinov/hibernate-join-bug.
Put any version of Hibernate to pom.xml, run 'mvn test' and look to invalid SQL generated by criteria.

Guram SavinovMay 9, 2013 at 3:27 PM
What this issue status today? Why this issue have 'fixed' status?
Hibernate (all versions) still generate invalid SQL for criteria when used composite primary key many-to-one property.
Steve EbersoleNovember 1, 2012 at 2:18 PM
Alex, maybe. Please attach a test showing the problem to a new issue. As I said above, here I only addressed the invalid SQL aspect.
I did the append("")
because I was nervous about the same path instance being reused. And as it passes all of our existing tests it seemed to be fine. Really I guess I could/should of added a clone()
override. Anyway a test would help resolve it.

Alex KalashnikovNovember 1, 2012 at 12:55 PM
,
could you look at JoinWalker.java:564 in 4.1.8.Final, please
shouldn't it be "path" instead of "path.append( "" )"
because now I receive ".." substring in path and so it couldn't be found in associationPathCriteriaMap and as a result joinType becomes JoinType.NONE
Steve EbersoleOctober 31, 2012 at 5:03 PM
Not sure; we'd have to look to see which hash that build pulled from git. But, I can tell you it will be in today's 4.1.8 release which Brett will start in a few hours.
Btw, there were 2 issues here really rather than just one. I only addressed the invalid SQL generation. The other issue has to do with using property paths versus property names. It is not a bug and would need separate "Improvement" issue. As an example from the test I used:
tries to use a "property path" as a restriction. This instead needs to be:
Details
Assignee
Steve EbersoleSteve EbersoleReporter
Joris VerschoorJoris VerschoorTime tracking
2.1h loggedComponents
Fix versions
Affects versions
Priority
Major
Details
Details
Assignee
Reporter

We have a class Price that has a composite-id using a couple of key-properties and some key-many-to-ones)
One of those is "transportation", which has a many-to-one to transportationType
When we query using: criteria.add(Expression.eq("price.transportation.transportationType.id", transId);, we get an invalid SQL statement: The table of transportation was not selected.
I will try to make a testcase today or tomorrow, depending on my schedule.. Things will be more clear by then...
We have created a work-around, by mapping the transportationID twice: once in key-property, and once as a many-to-one. (instead of one key-many-to-one)