Announcement Announcement Module
Collapse
No announcement yet.
declarative transactions with HibernateTemplate Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • declarative transactions with HibernateTemplate

    I've search whole forum and still don't know what is wrong in my settings.

    I want to use declarative transactions in my application, but from debug file I think that transactions don't even start (they start for single sessions which are related to single HibernateTemplates) and don't know why.

    Here are my configuration code:
    Code:
            <bean id="userDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> 
      			<property name="driverClassName">
    				<value>${db.driver}</value>
    			</property>
    			<property name="url">
    				<value>${db.url}</value>
    			</property>
    			<property name="username">
    				<value>${user.name}</value>
    			</property>
    			<property name="password">
    				<value>${user.password}</value>
    			</property>
    			<property name="maxActive">
    				<value>8</value>
    			</property>
      	</bean> 
    
    
    
    
               <bean id="userSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">				
    		<property name="dataSource"><ref local="userDataSource"/></property>
    		<property name="configLocation">
    			<value>/WEB-INF/bivela.cfg.xml</value>
    		</property>
    		<property name="hibernateProperties">
    			<props>						
    				<prop key="hibernate.dialect">${hibernate.dialect}</prop>
    				<prop key="hibernate.show_sql">true</prop>
    				<!-- <prop key="hibernate.use_outer_join">false</prop>				-->
    			</props>
    		</property>
    	</bean>
    	
    
               <bean id="userFacade" class="org.spring.facade.UserFacade">
    		<property name="sessionFactory"><ref bean="userSessionFactory" /></property>
    	</bean>
    Transactions:
    Code:
               <bean id="userTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    		<property name="sessionFactory">
    			<ref bean="sessionFactory" />
    		</property>
    	</bean>
    
             
              <bean id="transactionsInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
    		<property name="transactionManager"><ref local="userTransactionManager" /></property>
    		<property name="transactionAttributeSource">
    			<value>
    				org.spring.facade.UserFacadeInterface.updateCompanyInfo=PROPAGATION_REQUIRED
    			</value>
    		</property>
    	</bean>
    
    
    
               <bean id="userFactoryBean" class="org.springframework.aop.framework.ProxyFactoryBean">
    		<property name="proxyInterfaces">
    			<value>org.spring.facade.UserFacadeInterface</value>			
    		</property>
    		<property name="target"><value>userFacade</value></property>
    		<property name="interceptorNames">
    			<value>transactionsInterceptor</value>
    		</property>
    	</bean>

    And my 'userFacade' class looks like:
    Code:
    public class UserFacade extends HibernateDaoSupport implements
    		UserFacadeInterface {
    ...
    
    public void updateCompanyInfo(Companies company, int countryId){
    		List countryList = getHibernateTemplate().find("from Countries country" +
    				" WHERE country.id = ?", countryId);
    		if(!(countryList.isEmpty())){
    			Countries country = (Countries)countryList.get(0);
    			company.setCountry(country);
    			CompaniesArchive archive = new CompaniesArchive(company);
    			archive.setCompaniesId(company);
    			getHibernateTemplate().save(archive);
    			getHibernateTemplate().update(company);			
    		}
    	}
    	
    ...
    
    }

    What am I doing wrong that there isn't single transaction for this method?

    Thanks in advance for your tips.
    martique

  • #2
    I'm not sure I understand what you are saying. Is there any chance you can explain it again and show what makes you think there is a problem here. I'd also have a look at some of the options regarding transaction configuration, you can cut down the amount of XML.
    http://forum.springframework.org/showthread.php?t=37178
    Last edited by karldmoore; Aug 30th, 2007, 06:27 AM.

    Comment

    Working...
    X