1

I'm using Hibernte 4.3.x.

If I try to remove(delete) a object from DB = EM.remove(entity) the object will keep in DB (remove not executed) if Hibernate find references in the managed objects in the Entity Manager Context. (to avoid data inconsistency I guess)

Is it possible with configuration/settings (I found nothing so far) that the transaction throws a exception that remove was not possible because of found references?

(this has nothing to do with cascading/remove)

edit: Example

EM.remove(ObjectA.getObjectB());

If the transaction is executed. All seams fine no exception is thrown. As a "beginner" I expect that the ObjectB is deleted. But it isn’t. It's still there. The EM "see" that there is still a reference from ObjectA to ObjectB and dosn't execute the delete.

If I say to the EM it should persist or remove something and that is not possible I want know this.

(I know with ObjectA.setObjectB(null) the example works)

  • Probably, you are not committing the transaction, try to perform this operation in the transaction boundaries. – Zeus Jun 16 '14 at 22:43
  • @Zeus. The remove is called within a Transaction. But don't get a info back that the process was not successful. If I Persist an object and this was not successful an error is thrown, if a remove was not successful. you don't notice this. and wonder later why data is still there. – DavidLightman Jun 17 '14 at 16:15
  • What error does it throw? – Zeus Jun 17 '14 at 16:40

1 Answers1

0

If your question is really about if you can catch an exception no matter what... you can use the following:

try
{
  // your code...
  DB = EM.remove(entity)
}
catch(Exception e)
{
  System.out.println(e.printStackTrace());
}
catch(Throwable t)
{ // This one catches unchecked exceptions
  System.out.println(t.printStackTrace())
}

This can give you more informtion about what is going on...

raven99
  • 261
  • 3
  • 8