Hello
I have just started using Hibernate 3 along with Spring framework using MyEclipse and Oracle 10g.
I have started with a basic application having a single database table
Customer which is represented by an annotation based POJO. Then created a simple DataAccessObject
CustomerDAOImpl and an interface for that DAO
CustomerDAO. CustomerDAOImpl implements the methods of CustomerDAO and extends the HibernateDaoSupport. It also contains the methods to add/modify/remove/find records from the database.
In CustomerDAOImpl i want to specify the general transactional behavior so above the class definition I have put the following:
Code:
@Transactional(propagation=Propagation.SUPPORTS, readOnly=true)
public class CustomerDAOImpl extends HibernateDaoSupport implements CustomerDAO
I believe this would specify the general behaviour for all the methods in this class. If I want to change this behaviour for a specific method like in case of an add method, I will have to specify that on that method as follows:
Code:
@Transactional(propagation=Propagation.REQUIRED, readOnly=false)
public Customer insertCustomer(Customer customer)
Now my question is:
1. The approach I have used to specify the transactional behaviour, is this approach correct?
2. Since CustomerDAOImpl methods are an implementation of the CustomerDAO interface, should I specify this transactional behavior also on the methods of the interface like:
Code:
@Transactional(propagation=Propagation.REQUIRED, readOnly=false)
Contact insertContact(Contact contact);
Or is it not required to specify it on top of interface methods?
Many Thanks
Rabbia