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:
Hibernate generates the correct SQL:
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.