java - Transactions and detach objects JPA -
good morning in timezone.
technologies : ejb 3.0 jpa provider ->(openjpa) container -> snippet of code:
@stateless(name = "ejb/beanname") public class implements ainterface{ @persistencecontext(unitname = "main") private entitymanager emanager; public string getdata(d d){ try{ c c = new c(); f f = emanager.find(f.class,d.getid());(1) f.setsomedata(c);(2) getmethodtwo(d,f);(3) }finally{ emanager.clear();(5) } } public string getmethodtwo(d d,f f){ query q = emanager.createnativequery("update ..."); q.executeupdate();(4) } }
in company project , making changes snippet of code. changes creation of method "getmethodtwo" , invocation(3).the problem in pace (4) jpa throws exception because there changes on object "f" loaded through entitymanager(1), attached context, , because there changes when call executeupdate(4) jpa try run sql statements of changes on object "f".before changes , code works because there finalize clear persistence context(5).i think poor way of code. know if call entitymanager.clear() before call method work think not right solution , right way of using jpa. should ?
best regards in advance
you should flush object state db before calling update.
emanager.flush();
and refresh state after operation
emanager.refresh(f)
Comments
Post a Comment