Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Use of @Transactional in Hibernate Data Access Object

843834Nov 5 2009 — edited Nov 5 2009
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:
@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:
@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:
@Transactional(propagation=Propagation.REQUIRED, readOnly=false)
   Customer insertCustomer(Customer customer);
Or is it not required to specify it on top of interface methods?

Many Thanks
Rabbia

Edited by: rabbia on Nov 5, 2009 1:07 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 3 2009
Added on Nov 5 2009
0 comments
288 views