Hi all. I wrote a question over on stack:
I hope it’s ok to ask the experts here?
My basic question is this:
If I have batch of 10 entities I persist to the session cache (e.g. Session.persist(object) ).
And lets say that one of the items in the batch is invalid. In my specific case, some of the data in the object exceeds the length of one more fields in one or more tables, to it throws an DataException.
Lets say I flush after my batch of 10 (e.g. Session.flush() );
The exception is thrown. If I capture the exception, what is the state of those entities that I tried to flush?
Did some of the data get saved to the DB? What is the state of the entity that caused the exception?
I am only issuing a commit every 250 records, so rolling back the entire transaction would undo a significant amount of work.
What I am aiming to do is to “manually” rollback the last batch by de-persisting those entities and then issuing a commit after each save. I’ll gracefully handle the exception for the problem entity; this way I loose one record versus 10.
The problem I’m facing is that session.delete/remove/detach/evict(); I can’t seem to figure out which one actually does the trick. When I try to re-persist the objects that I think i’ve deleted, I end up with a constraint violation.