File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Java Interview Guide this week in the Jobs Discussion 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)
I agree. Here's the link:
subject: many-to-one relationship to non-PK field
It's not a secret anymore!