0

I'm new in JPA/Hibernate. I'm using EntityManager. I read that if a transaction failed to update, it must rollback. It make sense for updating multi tables, but if I want to update only one table, do I need to rollback the transaction?

Roland Rácz
  • 2,879
  • 3
  • 18
  • 44
Fotis Tasou
  • 5
  • 2
  • 7
  • It depends on your needs. If it is OK to keep the state even if one of updates to same table has failed then you don't have to rollback. However in most IRL-cases this should be considered as corrupted state and be rolled back. Imagine the situation when you and 2 your pals came to the night-club but the guards don't let you get in because of dirty shoes... is it OK if your pals get in anyway and you stay out? Or they should come out and stay with you (and not be "inserted into NightClubVisitors table" :-) ) ? – Nikolai Shevchenko Feb 20 '18 at 16:45
  • ok thnk.I want if an update failed in the table NightClubeVistior all the updates of this table to failed , so i need to rollback – Fotis Tasou Feb 20 '18 at 17:02
  • In this case the transaction only includes you and your friends, please don't force existing visitors to be kicked out in the middle of the party :D – Nikolai Shevchenko Feb 20 '18 at 17:05

0 Answers0