Saturday, 15 March 2014

java ee - JPA ManyToOne with composite key -



java ee - JPA ManyToOne with composite key -

i have model mapping brand entity:

@entity public class brand implements serializable { private static final long serialversionuid = 1l; @embeddedid private brandpk id; //... }

the composite key is:

@embeddable public class brandpk implements serializable { private static final long serialversionuid = 1l; private int id1; private int id2; //... }

now want bring together product entity (one brand, many products):

i have:

@entity public class product implements serializable { private static final long serialversionuid = 1l; @id @generatedvalue(strategy=generationtype.auto) private int id; @manytoone // ??? private brand brand; //... }

what need correctly bring together tables-entities?

table_brands has pk composing 2 fields: id1 , id2 table_products has pk id, , field id_brand refering id1.

id2 not used anymore , not of import @ all!

this mapping legacy db unfortunately cannot change, need bring together "ignoring" id2. how can i?

if add together column id_brand2 referring id2, can seek this:

@manytoone @joincolumns({ @joincolumn(name="id_brand", referencedcolumnname="id1"), @joincolumn(name="id_brand2", referencedcolumnname="id2") }) private brand brand;

java-ee jpa orm

No comments:

Post a Comment