spring3.1+hibernate3.6.9+atomikos3.7.0配置JTA事务

其他依赖:略

添加依赖

<dependency>
		<groupId>com.atomikos</groupId>
		<artifactId>transactions-jdbc</artifactId>
                <version>3.7.0</version>
</dependency>
<dependency>
		<groupId>javax.transaction</groupId>
		<artifactId>jta</artifactId>
               <version>1.1</version>
</dependency>

jta属性文件配置:

com.atomikos.icatch.service = com.atomikos.icatch.standalone.UserTransactionServiceFactory
com.atomikos.icatch.console_file_name = tm.out
com.atomikos.icatch.log_base_name = tmlog 
com.atomikos.icatch.tm_unique_name = com.atomikos.spring.jdbc.tm 
com.atomikos.icatch.console_log_level = INFO
com.atomikos.icatch.max_timeout = 300000

 数据源配置:

 

<!-- 数据源配置,druid数据库连接池 -->
	<bean id="dataSourceYuanshiKu" class="com.atomikos.jdbc.AtomikosDataSourceBean"
		init-method="init" destroy-method="close">
		 <property name="uniqueResourceName">      
            <value>jdbc/dataSourceYuanshiKu</value>      
        </property>      
        <property name="xaDataSourceClassName">      
            <value>${jdbc.oracle.xaDataSourceClassName}</value>      
        </property>      
        <property name="xaProperties">      
           <props>    
                   <prop key="URL">${jdbc.yuanshiku.url}</prop>    
	               <prop key="user">${jdbc.yuanshiku.userName}</prop>    
	               <prop key="password">${jdbc.yuanshiku.userPsw}</prop>    
           </props>      
        </property>          
        <property name="poolSize">      
            <value>3</value>      
        </property> 
        <property name="maxPoolSize"><value>30</value></property>    
	</bean>
	
	<!-- sessionFactory设置 -->
	<bean id="sessionFactoryYuanshiKu"
		class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
		<property name="dataSource">
			<ref bean="dataSourceYuanshiKu" />
		</property>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">${hibernate.oracle.dialect}</prop>
				<prop key="hibernate.hbm2ddl.auto">${hibernate.yuanshiku.hbm2ddl.auto}</prop>
				<prop key="hibernate.show_sql">${hibernate.yuanshiku.show_sql}</prop>
				<prop key="hibernate.format_sql">${hibernate.yuanshiku.format_sql}</prop>
			</props>
		</property>
		<property name="packagesToScan">
			<value>com.szwx.credit.yuanshiku.model</value>
		</property>
	</bean>

 事务配置:

 

 

<!-- JTA事务BEGIN -->
	<bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager"
		init-method="init" destroy-method="close">
		<property name="forceShutdown">
			<value>true</value>
		</property>
	</bean>
	<bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp">
		<property name="transactionTimeout" value="300" />
	</bean>
	<bean id="transactionManager"
		class="org.springframework.transaction.jta.JtaTransactionManager">
		<property name="transactionManager" ref="atomikosTransactionManager" />
		<property name="userTransaction" ref="atomikosUserTransaction" />
		<property name="allowCustomIsolationLevels" value="true" />
	</bean>
	<!-- JTA事务END -->

	<tx:advice id="txAdviceSystem" transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="save*" propagation="REQUIRED" />
			<tx:method name="add*" propagation="REQUIRED" />
			<tx:method name="create*" propagation="REQUIRED" />
			<tx:method name="insert*" propagation="REQUIRED" />
			<tx:method name="update*" propagation="REQUIRED" />
			<tx:method name="merge*" propagation="REQUIRED" />
			<tx:method name="del*" propagation="REQUIRED" />
			<tx:method name="remove*" propagation="REQUIRED" />
			<tx:method name="put*" propagation="REQUIRED" />
			<tx:method name="use*" propagation="REQUIRED" /><!--hibernate4必须配置为开启事务否则 
				getCurrentSession()获取不到 -->
			<tx:method name="get*" propagation="REQUIRED" read-only="true" />
			<tx:method name="count*" propagation="REQUIRED" read-only="true" />
			<tx:method name="find*" propagation="REQUIRED" read-only="true" />
			<tx:method name="list*" propagation="REQUIRED" read-only="true" />
			<tx:method name="*" read-only="true" />
		</tx:attributes>
	</tx:advice>
	<!-- 只对业务逻辑层实施事务 -->
	<aop:config expose-proxy="true">
		<aop:pointcut id="txPointcutSystem"
			expression="execution(* com.szwx.credit.*.service.impl.*Service.*(..))" />
		<aop:advisor advice-ref="txAdviceSystem" pointcut-ref="txPointcutSystem" />
	</aop:config>

oracle数据库需添加授权

grant select on sys.dba_pending_transactions to testdatabase;
grant select on sys.pending_trans$ to testdatabase;
grant select on sys.dba_2pc_pending to testdatabase;
grant execute on sys.dbms_system to testdatabase; 

 

 

你可能感兴趣的:(hibernate3)