K
kamiseq
hi,
I have very strange behaviour with my JPA entities.
I have to entities GenObject and GenObjectCnf that are linked with one-
to-many type, where in GenObject
@OrderBy
@OneToMany(cascade = CascadeType.ALL, mappedBy = "objects", fetch =
FetchType.LAZY)
private List<GenObjectCfg> objectsCfgSet = new ArrayList<GenObjectCfg>
();
now I create GenObject and persist it. then I instantiate new
GenObjectCnf object assign GenObject with it and persist. so in the db
everything is fine data is saved and I can move on. transaction is
over and my objects are detached from session.
the problem is now that my GenObject doesn't know about GenObjectCnf
as it was created before it and I didn't assigned GenObjectCnf back
after I created it. so I thought I can simply merge GenObject object
to update its state and data I need. so in other transaction Im
calling
this.em.merge(object);
GenObjectCfg parentCfg = object.getObjectsCfgSet().get(0);
as it should fetch all GenObjectCnf related to this GenObject object.
but is not and list remain empty.
BUT when I call
GenObject go = this.em.find(GenObject.class, object.getIdObject());
GenObjectCfg parentCfg = go.getObjectsCfgSet().get(0);
data is fetched and I get what I want, so essentially what am I
missing??
why is it so??
Im really out of ideas and it is something about how JPA works and I
didnt learn that yet, doesnt it?!
I have very strange behaviour with my JPA entities.
I have to entities GenObject and GenObjectCnf that are linked with one-
to-many type, where in GenObject
@OrderBy
@OneToMany(cascade = CascadeType.ALL, mappedBy = "objects", fetch =
FetchType.LAZY)
private List<GenObjectCfg> objectsCfgSet = new ArrayList<GenObjectCfg>
();
now I create GenObject and persist it. then I instantiate new
GenObjectCnf object assign GenObject with it and persist. so in the db
everything is fine data is saved and I can move on. transaction is
over and my objects are detached from session.
the problem is now that my GenObject doesn't know about GenObjectCnf
as it was created before it and I didn't assigned GenObjectCnf back
after I created it. so I thought I can simply merge GenObject object
to update its state and data I need. so in other transaction Im
calling
this.em.merge(object);
GenObjectCfg parentCfg = object.getObjectsCfgSet().get(0);
as it should fetch all GenObjectCnf related to this GenObject object.
but is not and list remain empty.
BUT when I call
GenObject go = this.em.find(GenObject.class, object.getIdObject());
GenObjectCfg parentCfg = go.getObjectsCfgSet().get(0);
data is fetched and I get what I want, so essentially what am I
missing??
why is it so??
Im really out of ideas and it is something about how JPA works and I
didnt learn that yet, doesnt it?!