Tim Holloway wrote:Welcome to the JavaRanch, Luca!
Aren't you missing something from that stacktrace? When I get a Hibernate JPA rollback exception, it's chained to the exception that initiated the rollback.
Tim Holloway wrote:
I'm sure I've missed some details. It's hard to follow stuff that's too big to be seen all at once on the same screen, but I understand that you are committing the parent and child in separate operations. You would be better off doing them both in a single transaction.
In the case of a one-to-many transaction, if you have the correct options set on your entity definitions, committing the parent will automatically commit the child objects. You do need to have the parent and child relationships properly set in your object model when you do this, though. Also, when updating parent-child sets where children may be removed as well as added, JPA2 added an "orphanRemoval" option to get around the case where the in-memory database model gets out of sync with the actual database because removed objects are not by default disconnected from the parent for historical reasons. Several other "gotcha's" apply as well, but when properly set up, it's like magic.