Saturday, 15 August 2015

jpa - GWT RequestFactory: updates not propagated to cascaded object -



jpa - GWT RequestFactory: updates not propagated to cascaded object -

i have entity company referenced object itemversion , utilize jpa (eclipselink) persistence layer. code extract given here:

@entity public class company{ private string instance; @onetoone(cascade = cascadetype.all) @joincolumn(name = "fk_item_version_id") private itemversion itemversion; } @entity public class itemversion{ private string comment; ... }

i can create company object , persist it. can find new object, update attribute "instance" , persist , works fine. when alter attribute "comment" of referenced itemversion object, alter not stored on server side.

the create/update test code looks like:

final eventbus eventbus = new simpleeventbus(); final aftdrequestfactory requestfactory = gwt.create(aftdrequestfactory.class); requestfactory.initialize(eventbus); final companyrequest request = requestfactory.companyrequest(); final companyproxy newcompany = request.create(companyproxy.class); newcompany.setinstance("1"); itemversionproxy newversion = request.create(itemversionproxy.class); newversion.setcomment("first comment"); newcompany.setitemversion(newversion); request.persist().using(newcompany).fire(new receiver<void>() { @override public void onsuccess(void arg0) { final companyrequest request2 = requestfactory.companyrequest(); request<companyproxy> p = request2.findcompany(1l).with("itemversion"); p.to(new receiver<companyproxy>() { @override public void onsuccess(companyproxy response) { final companyrequest request3 = requestfactory.companyrequest(); final companyproxy editablecompany2 = request3.edit(response); editablecompany2.setinstance("2"); editablecompany2.getitemversion().setversionnumber(2); request3.persist().using(editablecompany2).fire(new receiver<void>() { @override public void onsuccess(void arg0) { // persist company version system.out.println("company updated");

however, update "instance" , "comment" goes on wire (checked wich wireshark between client , server), in persist method of company, referenced itemversion object , "comment" attribute not updated while "instance" updated , hence old comment stored.

the persist method of company looks like:

public void persist() throws persistenceexception { entitymanager em = emf.createentitymanager(); entitytransaction tx = null; seek { tx = em.gettransaction(); tx.begin(); company existingentity = findcompany(getid()); if (existingentity == null) { em.persist(this); } else { setid(existingentity.getid()); em.merge(this); } tx.commit(); } grab (runtimeexception e) { tx.rollback(); throw e; }

the work around search , depending on search result em.persist or em.merge necessary, because simple persist not store updates.

you must utilize open-session-in-view/session-per-request pattern (i.e. sharing same entitymanager instance lifetime of request) requestfactory; see https://code.google.com/p/google-web-toolkit/issues/detail?id=7827 details.

gwt jpa requestfactory

No comments:

Post a Comment