java - null not allowed for column in join table with one entity extending another -
i have situation have entity vcenterdistributedvirtualportgroup extends vcenternetwork , both entities in onetomany relationship inside entity vcenterfolder. i'm getting following error:
caused by: org.h2.jdbc.jdbcsqlexception: null not allowed column "network_type"; sql statement: insert folder_network (folder_type, folder_val, distributedvirtualportgroups_type, distributedvirtualportgroups_val) values (?, ?, ?, ?) [23502-182]
vcenternetwork:
@entity @embeddable @table(name="network") @discriminatorcolumn(name="discriminator") @discriminatorvalue("network") public class vcenternetwork { @transient private network network; @transient private static map<mor, vcenternetwork> networkmap = new treemap<mor, vcenternetwork>(); @embeddedid private mor id; public mor getid() {return this.id;} public void setid(mor id) {this.id = id;} ... }
vcenterdistributedvirtualportgroup:
@entity @table(name="distributedvirtualportgroup") @discriminatorcolumn(name="discriminator") @discriminatorvalue("distributedvirtualportgroup") public class vcenterdistributedvirtualportgroup extends vcenternetwork { @transient private distributedvirtualportgroup distributedvirtualportgroup; @transient private static map<mor, vcenterdistributedvirtualportgroup> distributedvirtualportgroupmap = new treemap<mor, vcenterdistributedvirtualportgroup>(); ... }
vcenterfolder:
@entity @table(name="folder") public class vcenterfolder { @transient private folder folder; @transient private static map<mor, vcenterfolder> foldermap = new treemap<mor, vcenterfolder>(); @embeddedid private mor id; public mor getid() {return this.id;} public void setid(mor id) {this.id = id;} @embedded @onetomany(cascade=cascadetype.all) private list<vcenternetwork> network = new arraylist<vcenternetwork>(); public list<vcenternetwork> getnetwork() {return this.network;} public void getvirtualnetwork(list<vcenternetwork> network) {this.network = network;} @embedded @onetomany(cascade=cascadetype.all) private list<vcenterdistributedvirtualportgroup> distributedvirtualportgroups = new arraylist<vcenterdistributedvirtualportgroup>(); public list<vcenterdistributedvirtualportgroup> getdistributedvirtualportgroups() {return this.distributedvirtualportgroups;} public void setdistributedvirtualportgroups(list<vcenterdistributedvirtualportgroup> distributedvirtualportgroups){this.distributedvirtualportgroups = distributedvirtualportgroups;} .... }
this results in join table looks following:
folder_network folder_type - varchar(255) not null folder_val - varchar(255) not null network_type - varchar(255) not null network_val - varchar(255) not null distributedvirtualportgroup_type - varchar(255) not null distributedvirtualportgroup_type - varchar(255) not null
i'm new jpa, guess join table needed both vcenterfolder-vcenternetwork , vcenterfolder-vcenterdistributedvirtualportgroup, since vcenterdistributedvirtualportgroup extends vcenternetwork, it's building 1 join table both relations using different type/val pair each relation. assume 1 pair used @ time other being null. seems problem. seem me fields should either nullable or 2 sets of type/val pairs should merged one.
i assume there way round this, sure don't know is.
mor happens have members type & val, names in join table.
i solved problem adding folloing jointable on both network , distributedvirtualportgroups fields:
@jointable ( name="folder_network", joincolumns= {@joincolumn(name="type", referencedcolumnname="type"), @joincolumn(name="val", referencedcolumnname="val")}, inversejoincolumns= {@joincolumn(name="network_type", referencedcolumnname="type"), @joincolumn(name="network_val", referencedcolumnname="val")} )
Comments
Post a Comment