java - @JoinTable to use Imported Key instead of primary key -


using jpa/hibernate 3.6/db2.

i have got following exception: caused by: org.hibernate.annotationexception: secondarytable joincolumn cannot reference non primary key

caused by:

public class xrequest {   @manytoone   @jointable(     name = "requestbatch",     joincolumns = @joincolumn(name = "requestbatchid", referencedcolumnname="requestbatchid"),     inversejoincolumns = @joincolumn(name = "requestversionid")   )   private requestversion requestversion; } 

requestbatchid not primary key, imported key requestbatch table (and there, indeed primary key). why jointable have use primary key? mean, didn't define many-to-one association? why have primary key?

to specify: tables like.

xrequest ( requestid int (primary) requestbatchid int (imported key requestbatch) )  requestbatch ( requestbatchid int (primary) requestversionid int  )  requestversion ( requestversionid int (primary) ) 

the wanted outcome sql query built me hibernate:

select xr, rv  xrequest xr left outer join requestbatch rb on rb.requestbatchid = xr.requestbatchid  inner join requestversion rv on rb.requestversionid = rv.requestversionid 

if read jpa documentation on @jointable, see descriptions joincolumns , inversejoincolumns mention:

the foreign key columns of join table reference primary table of entity...

i guess enough understand constraints.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -