java - Re-Attaching detached objects in Playframework -
i have process user can create object (let's call a) , manipulate in several steps. user can add reference persisted entity object (let's call persisted entity b). not want persist in database unless last step has been finished, i'm caching after each step.
i using playframework java , jpa , b gets detached retrieve database, assign , cache a. after submitting last step, need have transient object b again in order persist it.
here exception
[persistenceexception: org.hibernate.persistentobjectexception: detached entity passed persist: models.b]
what best way archive that?
thanks in advance
i'm bit puzzled question. entity objects in detached state if ever been managed persistence context (eg: ever been saved / updated / retrieved database) or create new entity object , set primary key field. until entities transient. looking @ requirement why not keep transient (eg: save in http session) until last step , persist ?
on side note, if i'm not wrong difference between detached , transient primary key field. if have detached object , reset primary key field default (0 or null) can it's transient entity. under hood maybe there's object proxies leftover on detached entity not on transient, think should not affect behavior:
// start transaction a.. user u1 = new user("sam"); // u1 transient em.persist(u1); // u1 managed, database gives id 1 // commit , end transaction a.. em.detach(u1); // u1 detached // start transaction b.. user u2 = new user("sammy");// u2 transient u2.setid(1); // u2 can treated detached object of u1 because has same id em.merge(u2); // should updates user row id 1 name 'sam' 'sammy' // commit , end transaction b
Comments
Post a Comment