| The problem happens when you have an entity (B) that has a FK/@JoinColumn that points to a unique key of another entity (A) and this unique key is not the PK/@id of A. when I run this:
select b from B b join b.a a where a = :a
Hibernate generates the correct SQL:
select
b0_.uniqueKey_a as uniqueKe1_1_
from
B b0_
inner join
A a1_
on b0_.uniqueKey_a=a1_.uniqueKey // correct
where
a1_.primaryKey=? // wrong binding (should be primaryKey of argument)
Notice that the join is correctly made on the unique key, not the @id key. The error is in the binding. Instead of binding the id of the argument to the id column, it binds the unique key value of the argument to the id column.
Check the test case, it's very simple and you will understand what I'm trying to say here. The line above will only make sense if you look at the example. |