问题
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