java - JPA2.0 How to map a collection of an entity with inheritance mapped by TABLE_PER_CLASS -
i want map collection (a map) of entity inheritance. entity , inheriting entity that:
@entity public class testentity { @onetomany(mappedby = "parent") public map<string, mapvalueentity> map = new hashmap<string, mapvalueentity>(); @id @generatedvalue(strategy = auto) protected long id; public string name; public testentity() { } public testentity(string name) { this.name = name; } } @entity public class subentity extends testentity{ public subentity() { } string testsubentityname; public subentity(string name) { this.testsubentityname = name; } }
the entity used map value this
@entity public class mapvalueentity { testentity parent; @id @generatedvalue(strategy = auto) protected long id; public mapvalueentity() { } string subentityname; public mapvalueentity(string name) { this.subentityname = name; } }
and here test code:
entitymanager em = entitymanagerservice.getentitymanager(); em.gettransaction().begin(); (int = 0; < 10; i++) { testentity e = new testentity("mynameis" + i); (int j = 0; j < 8; j++) { mapvalueentity se = new mapvalueentity("iamno" + j + "." + i); e.map.put("key" + * 100 + j, se); se.parent = e; em.persist(se); } em.persist(e); } em.gettransaction().commit();
so far works fine. eclipselink puts testentity , subentity in 1 table discriminator column distinguishing between classes. , complete map data stored in table mapvalueentity. if change mapping strategy default (= single_table) table_per_class construction breaks:
@entity @inheritance(strategy = table_per_class) public class testentity { ...
the exception description says:
multiple writable mappings exist field [mapvalueentity.map_key]. 1 may defined writable, others must specified read-only.
do see chance use table_per_class strategy in scenario? mentioned "multiple writable mappings"?