Guy Emerson wrote:Would you please tell me what are the different ways of achieving this transaction management.
A very simple way to achieve this would be something like this. First create a
book method in a
FlightDao class which takes a
Flight object as a parameter (and a
Flight object has at least two instance variables:
from and
to). Then create a
book method in a
FlightService class which takes a list of
Flight objects as a parameter. In this method I would start a transaction and try to book each flight. If all flights are booked successfully, the transaction will be committed. But if one of the
book method invocations fails with an exception, the transaction will be rollbacked. The code could look like this
And then you can easily invoke the
book method in the
FlightService class with the appropriate flights
But maybe you want to have a look at the
Transactions and concurrency control chapter of the Hibernate User Guide to have a better understanding about transaction, (anti-)
patterns and common issues.
Hope it helps!
Kind regards,
Roel