论坛首页 Java企业应用论坛

Atomikos JTA for Hibernate3

浏览 4601 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-11-22  
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 时会出一些问题
   发表时间:2007-11-25  
  也有用atomikos做JTA,一切操作正常,但不知为什么停tomcat事老有:
Exception in thread "Thread-6" java.lang.NullPointerException
at com.atomikos.icatch.system.Configuration.removeResource(Unknown Source)
at com.atomikos.jdbc.JtaDataSourceImp.close(Unknown Source)
at com.atomikos.jdbc.DataSourceShutdownHook.run(Unknown Source)
Exception in thread "Thread-14" java.lang.NullPointerException
at com.atomikos.icatch.system.Configuration.removeResource(Unknown Source)
at com.atomikos.jdbc.JtaDataSourceImp.close(Unknown Source)
at com.atomikos.jdbc.DataSourceShutdownHook.run(Unknown Source)
错误,不知道是什么原因
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics