]
Steve Schols commented on HHH-5570:
-----------------------------------
Excuse me, spelling error.
Start of my explanation should be: We have to couple two tables on different legacy
databases...
org.hibernate.AnnotationException: SecondaryTable JoinColumn cannot
reference a non primary key
-----------------------------------------------------------------------------------------------
Key: HHH-5570
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5570
Project: Hibernate Core
Issue Type: Bug
Components: annotations
Affects Versions: 3.5.6
Environment: Hibernate-3.5.6-Final, HSQLDB
Reporter: Steve Schols
Attachments: Person.hbm.xml, Person.java
We have to couple to tables on different legacy databases.
One table is the Person table which has PERSON_ID as it's primary key. The other
table is the Farmer table which has FARMER_NUMBER as it's primary key.
We are unable to map this specific situation in HBM XML mapping files. Whatever we
configure, the generated SQL query will still join PERSON_ID = FARMER_NUMBER which always
gives 0 results. The PERSON_ID is just a technical identifier, where the FARMER_NUMBER is
a meaningfull business key.
I made a small Proof of Concept (PoC) about Person entities and PersonIdentification
entities (Social Security Number, Date of Birth, Gender, ...) using HBM XML files and
another PoC using JPA/Hibernate Annotations.
In the HBM XML PoC, the test went green but only because we generated the data ourselved
and because PERSON_ID and SOCIAL_SECURITY_NUMBER were generated the same by Hibernate. The
query did join PERSON_ID on SOCIAL_SECURITY_NUMBER.
In the Annotations PoC the test went red with the Exception mentioned in the summary:
org.hibernate.AnnotationException: SecondaryTable JoinColumn cannot reference a non
primary key
In this case, that's exactly what we want to accomplish on the legacy database. Join
the primary key of a secondary table (SOCIAL_SECURITY_NUMBER in
PERSON_IDENTIFICATION_TABLE) with a foreign key column (non-primary key) of a primary
table (SOCIAL_SECURITY_NUMBER in PERSON_TABLE).
We can work around this issue by making a separate class for the extra information and
mapping it as a OneToMany or OneToOne instead of holding the data in one class.
But we find the extra class a little bit redundant because it really contains PersonData.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: