jpa - Hibernate Using Merge on concurrent Update or Delete -


is there way me know if detached entity in session cache. have following scenario.

public void method (entity entityobject) {        //list associated objects , process             criteria criteria = session.createcriteria(groupmembers.class);        criteria.add(restrictions.eq("group", group));        criteria.createcriteria("group", "group", jointype.left_outer_join);        list<groupmembers> members = (list<groupmembers>) criteria.list();            ...          entityobject= (entity) session.merge(entityobject);          if (somecondition){         session.delete(entityobject);         }  } 

this works fine of time except in following scenario. entityobject deleted transaction. want session.delete(entityobject) fail because entityobject deleted. however, because of session.merge(entityobject) record inserted database if entity can not found in cache or db delete succeeds.


updated. works doing select @ beginning... way?

public void method (entity entityobject) {       entity entityobjectcopy = session.get(entity.class, entityobject.getid())         if(entityobjectcopy == null)        {        //list associated objects , process             criteria criteria = session.createcriteria(groupmembers.class);        criteria.add(restrictions.eq("group", group));        criteria.createcriteria("group", "group", jointype.left_outer_join);        list<groupmembers> members = (list<groupmembers>) criteria.list();            ...          entityobject= (entity) session.merge(entityobject);         }              if (somecondition){         session.delete(entityobject);         } } 


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -