i'm trying model simple onetoone relationship using jpa (eclipselink) , i'm geting exception java.lang.nosuchfieldexception description "an internal error occurred accessing primary key object".
tablea has onetoone relationship tableb. need have entity of tableb on tablea entity.
what i've tried
@namednativequeries(... ommitted breviety ...) @entity @table(name = "tablea") @cache(isolation = cacheisolationtype.isolated) public class tablea implements serializable { private static final long serialversionuid = 1l; @embeddedid private tablea_id id; //code part of composite embeded @onetoone @joincolumn(name = "code", insertable = false, updatable = false) private tableb b; //getters + setters @namednativequeries(... ommitted breviety ...) @entity @table(name = "tableb") @cache(isolation = cacheisolationtype.isolated) public class tableb implements serializable { private static final long serialversionuid = 1l; @id @column(name = "code") private string code; @column(name = "description") private string description; //getters + setters exception:
exception [eclipselink-0] (eclipse persistence services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.descriptorexception exception description: internal error occurred accessing primary key object [202]. internal exception: java.lang.nosuchfieldexception: b descriptor: relationaldescriptor(com.foo.tablea --> [databasetable(tablea)]) it may worth noting; there no foreign key defeined between code on tablea , tableb; don't have ability change that.
you have no foreign key in table referring table b, therefore cannot have join column on table have done.
@onetoone @joincolumn(name = "code", insertable = false, updatable = false) private tableb b; this statement requires join column ‘code’ in table – in table b not found jpa , therefore exception.
java.lang.nosuchfieldexception: b you require tableb entity field in tablea, , have stated cannot add foreign key tablea. should not big issue in case join can on either side of relationship.
given restrictions, can make relationship bidirectional owning side being tableb (the side contains join) , inverse side tablea.
try following:
@entity @table(name = "tableb") public class tableb …… //owning side of relationship @joincolumn annotation. @onetoone @joincolumn(name = "code", insertable = false, updatable = false) private tablea tablea; @entity @table(name = "tablea") public class tablea …….. //inverse side of relationship mappedby attribute. @onetoone(mappedby = tablea) private tableb tableb;
Comments
Post a Comment