Hi Anu, The JPA spec indicates that this FK to a non-PK relationship is not standard across vendors. From the section on the JoinColumn annotation:
*"If the referencedColumnName element is missing, the foreign key is assumed to refer to the primary key of the referenced table. Support for referenced columns that are not primary key columns of the referenced table is optional. Applications that use such mappings will not be portable." * According to the OpenJPA documentation [1], this non-standard join should be supported, but I have not personally tried it. You said that you tried the column reference, but it didn't work.. Was your usage consistent with the documentation? Also, what version of OpenJPA are you using? Good luck, Kevin [1] http://openjpa.apache.org/builds/latest/docs/docbook/manual.html#ref_guide_mapping_notes_nonstdjoins On Tue, Jun 5, 2012 at 6:18 PM, manushka <padk...@gmail.com> wrote: > Hello, > > I have a db foreign key pointing to a Unique key and not a Primary key of > the referenced table, > Tried column reference but it does not work. > At the time of the insert on the child record, the INSERT statement shows > that it is trying to insert the primary key of the referenced table. > The PK is int where as the unique key is a varchar, so it naturally bombs. > > Is there away to deal with this scenario or it is not valid for JPA/OPEN > JPA via the relationships. > > Regards'- Anu > > -- > View this message in context: > http://openjpa.208410.n2.nabble.com/Foreign-key-to-Unique-Key-Not-working-tp7580216.html > Sent from the OpenJPA Users mailing list archive at Nabble.com. >