JPA - strange behavior using EntityManager remove() method

蹲街弑〆低调 提交于 2019-12-13 04:16:28

问题


I am in a configuration (JTA - CMT) in which I have to remove an entity object after creating it. I use em.remove(object) after finding it, but remove doesn't work, or it seems to be not working.

What happens is that the object I want and try, to remove is still in DB.

Once the removal operation is performed, if I later try to retrieve the records from the entity table it belongs to, I GET THIS OBJECT (obviously with the other objects I previously saved). My check into the entity table, accessing by a shell the DB, confirms that objects I had to remove are stored in the table. It's strange. But if I try to do a little test - inside the method that calls remove() - of retrieving the object, right after calling remove() on it, by a new call to find(), the system, rightly, returns null (it says me that that object does not exist).

MyEntity object = em.find(MyEntity.class, my_entity_id);  // it is found
if (object != null) {
    em.remove(object);
    log.debug("something here");
} else
    log.debug("something else here");

// here i am testing whether it is still existing
object = em.find(MyEntity.class, my_entity_id);  // it is not found, returns null

I try also with using flush() right after remove() but nothing changes, actually an error emerges:

"java.sql.SQLException: IJ031070: Transaction cannot proceed: STATUS_MARKED_ROLLBACK"

Is there anyone that has encountered this situation? Any suggestion?

来源:https://stackoverflow.com/questions/54785923/jpa-strange-behavior-using-entitymanager-remove-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!