Transactions are a very important part of database design. In most cases, they are used to enforce data integrity. There are a few important design decisions you should consider when you are implementing transactions. First of all, DAO classes and methods should be very granular, and therefore should result in just one insert or update statement. It then follows that transactions should be managed by the Business Tier.
Consider this scenario: you need to create a record for a test record and test detail. Each test must have at least one detail, making it a 1:N relationship. Let the Test bean represent the test domain object and TestDetail represent the test detail domain object. The Test object has a List property that holds a collection of TestDetail objects. You want to insert the test and its details into the database, and to ensure the data integrity, you want to use transactions. However, you should not extend the scope of the TestDao interface so that you can insert the test details.
Instead, create a separate DAO for TestDetail and implement the insert(TestDetail) method. Then create a TestManager object that has properties for TestDao and TestDetailDao and uses Spring to automatically manage transactions.
For further discussion of transaction management, refer to Chapter 12.