欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Atomikos JTA for Hibernate3 博客分类: 技术 SpringHibernateJDBCMySQLthread 

程序员文章站 2024-03-18 20:46:34
...
http://wiki.atomikos.org/bin/view.pl/Main/HibernateIntegration#With_Spring

http://www.hibernate.org/hib_docs/v3/reference/en/html/transactions.html#transactions-connection-release

经过多次试验, 下面的配置是最合适的 (OpenSessionInView Works fine)

jta.properties
com.atomikos.icatch.service = com.atomikos.icatch.standalone.UserTransactionServiceFactory

#Do you want transaction logging to be enabled or not?
#If set to false, then no logging overhead will be done
#at the risk of losing data after restart or crash.
#Note: this setting may be overridden depending on your license!
com.atomikos.icatch.enable_logging = false
com.atomikos.icatch.automatic_resource_registration = true


xa datasource and jta transaction manager
	<bean id="system.datasource"
		class="com.atomikos.jdbc.SimpleDataSourceBean" init-method="init" destroy-method="close">
		<property name="uniqueResourceName"><value>XADBMS</value></property>
		<property name="xaDataSourceClassName">
			<value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value>
		</property>
		<property name="xaDataSourceProperties">
			<value>url=${jdbc.url};user=${jdbc.username};password=${jdbc.password};pinGlobalTxToPhysicalConnection=true</value>
		</property>
		<property name="exclusiveConnectionMode"><value>false</value></property>
		<property name="connectionPoolSize"><value>10</value></property>
	</bean>


	<bean id="system.sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="dataSource" ref="system.datasource"/>
		<property name="jtaTransactionManager" ref="atomikosTransactionManager" />
		<property name="mappingDirectoryLocations">
            <list>
            <value>classpath:/com/coheg/</value>
            </list>
        </property>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.query.substitutions">true ${boolean.true.value}, false ${boolean.false.value}, yes ${boolean.true.value}, no ${boolean.false.value}</prop>
				<prop key="hibernate.dialect">${hibernate.dialect}</prop>
				<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
				<prop key="hibernate.format_sql">true</prop>
				<!-- for jta compatilibility -->
				<prop key="current_session_context_class">jta</prop>		
				<prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</prop>	
				<prop key="hibernate.connection.release_mode">after_statement</prop>
			</props>
		</property>
	</bean>
	

	<!-- Construct Atomikos UserTransactionManager, needed to configure Spring -->
	<bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager" init-method="init" destroy-method="close">
		<!--  when close is called, should we force transactions to terminate or not? -->
		<property name="forceShutdown"><value>true</value></property>
	</bean>
	
	<!-- Also use Atomikos UserTransactionImp, needed to configure Spring  --> 
	<bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp">
	    <property name="transactionTimeout"><value>120000</value></property>
	</bean>
	
	<!-- Configure the Spring framework to use JTA transactions from Atomikos -->
	<bean id="system.platformTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
		<property name="transactionManager"><ref bean="atomikosTransactionManager"  /></property>
		<property name="userTransaction"><ref bean="atomikosUserTransaction"  /></property>
	</bean>
	



hibernate2 不支持 Connection Release Mode 概念, 在使用 JTA + OpenSessionInView 时会出一些问题