hibernate - How to revert cached entity object to last persisted state? -


i have relatively run of mill mvc scenario view (jsf) loads list of managed entities in ejb via managed bean using namedquery defined in entity class. each entity modifiable in view, collection of represented primefaces component p:accordionpanel. in each tab of panel form allows updates corresponding entity:

jsf:

<p:accordionpanel id="entityaccordion" value="#{managedbean.entitylist}"      var="entity" multiple="false" dynamic="true" cache="true"> 

managed bean:

public list<appeal> getentitylist() {      //this loads entities db     return manager.getentitylist(this.parentid) } 

when user changes form values in view, ajax automatically updates cached entity in managed bean. commision of new values, however, triggered hitting submit button in form. between first form change , submission, state of cached entity object different corresponding db row. need implement reversion of db state form in case user changes mind , cancels changes. cannot merely refreshing view because me cached object managed bean, which, due ajax, identical in view -- need first refresh cached object last persisted in db , refresh view cached object.

so far, have tried several things, none of worked:

ejb:

//this fails because reconstructs new entity object  //but managed bean keeps binding old 1 public void refreshentity(entity entity) {      //i had prior refresh without says entity not managed     //but reconstructs instance rather refresh existing     entity result = this.entitymanager.find(entity.class, entity.getid());      this.entitymanager.refresh(result);      return result; }  //not sure why fails tried per jpa spec public void clearentity() {      this.entitymanager.clear();  } 

as can see in comment of first attempted solution, doesn't work because managed bean seems keep reference old object while ejb refresh method changes pointer of variable wholly new constructed object. hoping managed bean repoint new object after garbage collecting old 1 doesn't that, rendering refresh (at least way doing it) useless.

how can revert cached entity object last persisted state while keeping view bindings object?

it might useful mention using jpa api in our application, uses hibernate implementation in backend.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

Maven Javadoc 'Cannot find default setter' and fails -