I'm wondering if there is a way to set references on detached objects in
OpenJPA. I have a simple program with two entities and their corresponding
facades.

The Entities FormControlEntity and FormControlFieldEntity are related and
mapped with cascade=CascadeType.PERSIST.

-> After the call to findByKey(), the entity is detached and gets reattached
when merge() is called.

-> merge() calls EntityManager.merge()

---

//FIRST EXAMPLE - WORKS

FormControlFacade f = new FormControlFacade();
FormControlEntity f_ent = f.findByKey(20000l);
                
//okay
FormControlFieldEntity ff_ent = new FormControlFieldEntity();
f_ent.getFields().add(ff_ent);
                
f.merge(f_ent);


------------------------


//SECOND EXAMPLE - FAILS

FormControlFacade f = new FormControlFacade();
FormControlEntity f_ent = f.findByKey(20000l);

//bugged
FormControlFieldFacade ff = new FormControlFieldFacade();
FormControlFieldEntity ff_ent = ff.findByKey(200100l);
f_ent.getFields().add(ff_ent);

f.merge(f_ent);


The given instance "FormControlFieldEntity-FormControlFieldEntity-200100" is
not managed by this context.

---

Is there a way to set references on detached entities?
Can I tell OpenJPA to automatically merge entities that are not managed by
the context?

---

(With Toplink, the code works fine.)

Thanks a lot!
-- 
View this message in context: 
http://n2.nabble.com/Question%3A-Detach---Attach-tp790687p790687.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Reply via email to