Issue
I have a CSV file which contains around 10Mb data which I use to populate my entire database. Suppose If I encountered an error while reading a record from CSV file I need to abort all my committed transactions ?
In my project, I have a threshold like if 5% of my records in CSV go wrong I will abort all committed transactions associated with that CSV file else if less than 5% I will only take out that record a keep in a separate file.
pl let me know how to abort all committed transactions(involves 15+ DAO classes) in hibernate.
Thanks for the suggestions.
Solution
Once a transaction is comitted it can't be reversed. Not in Hibernate, not in any database!
To keep your operations reversible you need to keep them in the same single, not yet comitted transaction and if any (by default runtime) exception arises it will automatically be rollbacked and all changes reversed.
You tagged your question as Spring, in Spring you can use @Transactional annotation over the method, and all changes in that method will be reversed in case of any transaction, including other methods called from that method.
more here https://www.baeldung.com/transaction-configuration-with-jpa-and-spring
also there is any example here https://javamondays.com/spring-transactions-explained/
Answered By - J Asgarov