hibernate - How to refresh just entity children without refreshing entire entity? -
i have pretty clean cut parent-child case scenario in db, reflected in corresponding entity objects:
parent:
@entity @table(name="tbl_parent") @namedqueries(...) public class parent implements serializable { ... @onetomany(cascade = cascadetype.all, mappedby = "parent", fetch = fetchtype.eager) private list<child> childlist; ... public list<child> getchildren() { if(this.childlist != null) { collections.sort(this.childlist); } return this.childlist; }
child:
@entity @table(name="tbl_child") @namedqueries(...) public class child implements serializable, comparable<child> { ... @joincolumn(name = "parent_id", referencedcolumnname = "parent_id", insertable = true, updatable = false) @manytoone(optional = true) private parent parent;
as loading of child data performed jpa
framework specified above annotations, not need specify method load data -- when parent
loaded, child
ren loaded automatically.
however, looking way refresh children on demand without calling refresh of whole parent. when call getchildren()
on existing parent, method doesn't refresh children of time of request reuses loaded , cached data. can somehow induce refresh on children without reloading whole parent object?
we using straight jpa
but, understand, utilizes hibernate
libraries in backend.
you refresh children explicitly:
for (child child : parent.getchildren()) { entitymanager.refresh(child); }
Comments
Post a Comment