[hibernate-issues] [Hibernate-JIRA] Created: (HHH-5570) org.hibernate.AnnotationException: SecondaryTable JoinColumn cannot reference a non primary key

Steve Schols (JIRA) noreply at atlassian.com
Thu Sep 16 06:01:22 EDT 2010


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: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list