java - How to avoid automatic entity update on Hibernate ValidationException -


i having spring method: validating entity after constructing of object, fetched db.

@transactional(rollbackfor={validationexception.class})     public object approve(command command) throws validationexception {         object obj = merger.mergewithexistingobject(command); // fetching object db old values , construct new object          validatorservice.validate( obj ); // throws validationexception          return saveobject(obj);     } 

but unfortunately after validationexception thrown. values still persisted in db. how can avoid situtation.

you can evict entity on validationexception:

try {     validatorservice.validate( obj ); } catch (validationexception e) {     entitymanager.detach(obj);     //or hibernate api     //session.evict(obj);      throw e; } 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -