java - JAXB Unmarshalling Entities - References null -
i have 2 mapping classes (analogue jpa classes):
aelement.java
@xmltype(proporder = {"name", "children", }) @xmlrootelement(name = "a") @xmlaccessortype( xmlaccesstype.property) public class aelement implements serializable { private string name; private list<belement> children; @xmlelement(name = "metadatum") public list<belement> getchildren(){ homecoming children; } ... }
belement.java
@xmlrootelement(name = "b") @xmltype(proporder = {"name"}) public class belement implements serializable{ private string name; private aelement parent; ... }
a , b in onetomany relation. xml should this:
<a> <b></b> <b></b> </a>
if unmarshal xml, map jpa classes , persist database stored correctly except references. means b
stored without foreign key a
in database.
i'm using jpa hibernate. next jpa classes:
a.java
@entity public class implements serializable { @id @generatedvalue(strategy = generationtype.identity) private long id; @column private string name; @onetomany(fetch = fetchtype.eager, cascade = cascadetype.all, mappedby = "parent") private list<b> children; public list<b> getchildren(){ homecoming children; } ... }
b.java
@entity public class b implements serializable{ @id @generatedvalue(strategy = generationtype.identity) private long id; @column private string name; @manytoone(optional = true) @joincolumn(name = "a_id", referencedcolumnname = "id") private parent; ... }
looks have assign appropriate each b. solves problem.
a.getb().foreach(b -> b.seta(a));
i don't know if workaround? because have other entities children of b
.
java xml jpa jaxb unmarshalling
No comments:
Post a Comment