Announcement Announcement Module
Collapse
No announcement yet.
Weird @Transactional behaviour and a question Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Weird @Transactional behaviour and a question

    Hi to all,

    I recently changed my application architecture to use Datasource dynamic routing in a master-slave database configuration.

    I added an aspect over @Transactional annotated method in my service layer and switch the underlying datasource if the transactional annotation is readonly or not.

    It works pretty well but i noticed a weird behaviour overriding the defaultTimeout property of transactionManager.

    Hibernate uses following properties

    Code:
    ...
    <property name="hibernate.bytecode.use_reflection_optimizer">true</property>
    <property name="hibernate.transaction.factory_class"> org.hibernate.transaction.JDBCTransactionFactory </property>  
    <property name="hibernate.order_updates">true</property>
    ...
    while my spring applicationContext configuration is:

    Code:
    <!-- DATASOURCES -->
    <bean id="parentDataSource" class="org.springframework.jndi.JndiObjectFactoryBean"
    		abstract="true" />
    
    	<bean id="masterDataSource" parent="parentDataSource">
    		<property name="jndiName">
    			<value>java:/comp/env/jdbc/frontDBWriter</value>
    		</property>
    	</bean>
    
    	<bean id="slaveDataSource" parent="parentDataSource">
    		<property name="jndiName">
    			<value>java:/comp/env/jdbc/frontDB</value>
    		</property>
    	</bean>
    <!-- DATASOURCES -->
    
    <!-- SESSION FACTORY -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" primary="true">
    		<property name="dataSource">
    			<ref bean="dataSource" />
    		</property>
    		<property name="configLocation">
    			<value>classpath:com/oos/data/mapping/hibernate-tx.cfg.xml</value>
    		</property>
    		<property name="hibernateProperties">
    			<ref local="hibernateProperties" />
    		</property>
    	</bean>
    <!-- SESSION FACTORY -->
    <!-- TX MANAGER -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    		<property name="sessionFactory" ref="sessionFactory"/>
    	</bean>
    <!-- TX MANAGER -->
    <tx:annotation-driven  order="9" transaction-manager="transactionManager" />
    If I change my transactionManager bean xml to
    Code:
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    		<property name="sessionFactory" ref="sessionFactory"/>
                    <property name="defaultTimeout" value="30" />
    	</bean>
    adding the defaultTimeout with a value that i assume is in second (or at least is what is specified on the documentation) all my queries fail but if I don't put any value or a value like 3600 everything works fine...

    I didn't dig into the transaction manager source code but it looks like is using the value in milliseconds.

    The datasources are provided by jboss but I can't see any property in mysql-ds.xml that could override the timeout value.

    If you have any hint...

    The question of the subject is:

    In an environment like the one i described would it make sense to configure the hibernate property ConnectionReleaseMode or it is provided by HibernateTransactionManager??

    Thanks,
    Matteo
Working...
X