transactions across DAO classes
Posted on 2004-03-25
I have an e-commerce application which has all kinds of data access objects which roughly relate to tables in hte database.
For example I have a customer table and an address table
These relate to my customer and Address objects which have CustomerDAO and AddressDAO objects associated with them. Fine so far.
Each of the methods in my DAO objects open a connection to the database, do their thing (like an insert or an update) then release the connection.
The problem comes when I need to encapsulate the insertion of a customer and the insertion of an address into a transaction. A transaction can not be done over more than one continuous connection (I think). Should I be passing a connection object to these methods explicitly and only opening a new connection if it is null?
How do you do it?
Would EJBs help?