jpa - Hibernate Transaction Context with Struts2 Actions -


i have scenario where, struts2 action fetches model object back-end , puts in ognl stack , front end view updated data.

then change value in view corresponds model object , update. value saved using hibernate's getsession().update(model) method.

question : when model object read in ognl stack, transaction context closes , model object gets detached. why allowed save change using getsession().update(model)? think getsession().merge(model) should used.

please me understand ambiguity.

both methods can pass detached object parameter, if there's object in context given identifier, first method throws exception. read

update persistent instance identifier of given detached instance. if there persistent instance same identifier, exception thrown.

public void update(object object); 

the second method doesn't throw exception because loads not existing object identifier context, update it, , returns caller.

copy state of given object onto persistent object same identifier. if there no persistent instance associated session, loaded. return persistent instance. if given instance unsaved, save copy of , return newly persistent instance. given instance not become associated session.

public object merge(object object); 

Comments