-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Hibernate & Transaction Management
PostPosted: Thu Nov 05, 2009 7:18 am 
Newbie

Joined: Wed Apr 11, 2007 8:48 am
Posts: 13
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.