Hi,
In JPA/Hibernmate, I was wondering why do methods in EntityManger (e.g persist,merge) throw RuntimeExceptions(e.g. IllegalStateException, IllegalArgumentException) insteadof PersistenceException or an appropriate subclass of it? If I see the API doc, it looks valid to have RuneTimeExceptions subclasses being thrown, but in real scenario, we are loosing important information hanging underneath.
Here is an example that I would like to give.
In my database table, I have three columns, col1, col2 and col3. col1 is the Pk and col2 and col3 are Foreign Keys(FK) and are nullable.
Values in col2 and col3 are mutually exclusive and should be unique ids. For some reason, the values (ids) in col2 and col3 got generated as same.
Because of this, during a delete process, as I loop thru to delete each object, I got the following exception during merge operation
java.lang.IllegalArgumentException: org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): [com.test.impl.Test #14910fb3-df28-4f70-ab43-a559e81a125f]
org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): [com.test.impl.Test#05b35b80-141e-485c-9f39-a1d8902623b5]
Now, as you see,if in my DAO,if I catch PersistenceException, the above exception will go unhandled. My question is: should not the exception org.hibernate.ObjectDeletedException be part of PersistenceException rather than being subclassed from IllegalArgumentException?
Can someone please enlighten on this issue?
Thanks in advance.
raj
|