This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes many-to-one relationship to non-PK field Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "many-to-one relationship to non-PK field" Watch "many-to-one relationship to non-PK field" New topic

many-to-one relationship to non-PK field

Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
I'm trying to declare a foreign key relationship between two entities where the type is java.lang.String and the related entity field is not a primary key but is a unique field. If I attempt the same thing, but relating to a primary key field (by leaving off the property-ref attribute which defaults to the id), I have no problem.

I have narrowed down a test case in an attempt to solve this problem but to no avail. The problem is that 'schemaexport' will generate the two tables X and Y but will not create the relationship and I don't understand why (also, why it does the create the relationship when relating to a PK field). I am using the Microsoft type 4 driver for MS SQL Server 2000.

Please find below two source files annotated with XDoclet and corresponding mapping files. Any assistance is most appreciated.

Tony Morris
Java Q&A (FAQ, Trivia)
It is sorta covered in the JavaRanch Style Guide.
subject: many-to-one relationship to non-PK field
Similar Threads
Integrity constraint violation: for Hibernate Insert
1-to-M mapping confusion
Can't not instance class...
Error when saving relationship
Looking for a database to Java code generator