java - Hibernate Entitymanager remove elegantly without exception? -


is there more elegant way of avoiding javax.persistence.entitynotfoundexception when calling entitymanager.remove() on object may or may not exist in persistent state? trying avoid situation need make 2 queries remove object. cheating with:

void remove(string id) {     t model = entitymanager.getreference(type, id);     entitymanager.remove(model); } 

but throw exception if model not exist.

i could:

void remove(string id) {     t model = retrieve(id);     if(model != null)         entitymanager.remove(model); } 

but involve 2 queries (setting aside notion of cache now).

the possibility use query delete , clause. works fine, except jpa not call @predelete or @postdelete operations on object delete. assume don't want anyway, go query. if want call listeners, object (obviously) has loaded prior deletion.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -