I'm having problems using annotations to refer to a non-primary key set of columns in another table. The referenced columns are part of a unique key, so this should work.
I think this is one of the "edge case limitations" discussed in
bug ANN-623, where it's said that "non PK target is supported". Therefore I think this is a bug in Hibernate.
I would file a bug report, but the comment by Emmanuel Bernard on that bug, which was closed due to lack of a test case, says to post in the forum first, so I am. I have a reproducible test case (
JUnit class and
HBM mapping file).
The error that I get is:
org.hibernate.AnnotationException:
referencedColumnNames(project_id, site_id) of UserRole.projectSite
referencing ProjectSite not mapped to a single property
Which is in some sense true, because it's mapped to a <properties> element with a unique attribute, but this works when the mapping comes from an HBM file, and I can't find another way to do it (and keep the associations) from an annotated class.
Combined with bug
HHH-4595, which stops me from moving the referenced mapping from HBM to an annotated class, this has stopped my migration from HBM to annotations cold.
Please let me know if you can help, if you think this is a bug or not, or whether I should post to the bug tracker.