spring+hibernate+proxool+jta(jtm)
最近は会社の新プロジェクトの開発環境を配置しています。個人的にはproxoolのデータソースが使いやすいと思いますが、ネット上にはjtaの配置コードがありません。
そこで、個人的にまとめた後、以下の構成を記録しました。
以下の設定の各オープンソースバージョン
spring version 2.58
hibernate version 3.2
proxool version 0.9.1
この3つのバージョンは比較的に肝心で、もし問題があるならば、衝突が発生するかもしれません。
appication Contect-core.xmlデータソース構成:
jdbc.properties構成:
proxool.xml(proxool.v 4.xmlと同じ)構成:
そこで、個人的にまとめた後、以下の構成を記録しました。
以下の設定の各オープンソースバージョン
spring version 2.58
hibernate version 3.2
proxool version 0.9.1
この3つのバージョンは比較的に肝心で、もし問題があるならば、衝突が発生するかもしれません。
appication Contect-core.xmlデータソース構成:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"
default-autowire="byName">
<!-- JDBC Properties -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:com/*/resource/jdbc.properties" />
</bean>
<!-- JTA TransactionManager -->
<bean id="jotmJta" class="org.springframework.transaction.jta.JotmFactoryBean" />
<bean id="jtaTxManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="userTransaction" ref="jotmJta"/>
</bean>
<!-- Hibernate SessionFactory -->
<!-- V7 sessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!--
<property name="dataSource" ref="dataSource" />
<property name="configLocation">
<value>/WEB-INF/hibernate.cfg.xml</value>
</property>
-->
<property name="jtaTransactionManager" ref="jotmJta" />
<property name="mappingDirectoryLocations">
<list>
<value>classpath:/com/*/hbm/v7</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
${hibernate.dialect}
</prop>
<prop key="hibernate.show_sql">
${hibernate.show_sql}
</prop>
<prop key="hibernate.cache.provider_class">
${hibernate.cache.provider_class}
</prop>
<prop key="hibernate.connection.release_mode">
${hibernate.connection.release_mode}
</prop>
<prop key="hibernate.autoReconnect">
${hibernate.autoReconnect}
</prop>
<prop key="hibernate.bytecode.use_reflection_optimizer">
${hibernate.bytecode.use_reflection_optimizer}
</prop>
<prop key="hibernate.connection.autocommit">
${hibernate.connection.autocommit}
</prop>
<prop key="hibernate.proxool.xml">
${hibernate.proxool.xml}
</prop>
<prop key="hibernate.proxool.pool_alias">
${hibernate.proxool.pool_alias}
</prop>
</props>
</property>
</bean>
<!-- V4 sessionFactory -->
<bean id="sessionFactoryV4" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="mappingDirectoryLocations">
<list>
<value>classpath:/com/*/hbm/v4</value>
</list>
</property>
<property name="jtaTransactionManager" ref="jotmJta" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
${hibernate.dialect}
</prop>
<prop key="hibernate.show_sql">
${hibernate.show_sql}
</prop>
<prop key="hibernate.cache.provider_class">
${hibernate.cache.provider_class}
</prop>
<prop key="hibernate.connection.release_mode">
${hibernate.connection.release_mode}
</prop>
<prop key="hibernate.autoReconnect">
${hibernate.autoReconnect}
</prop>
<prop key="hibernate.bytecode.use_reflection_optimizer">
${hibernate.bytecode.use_reflection_optimizer}
</prop>
<prop key="hibernate.connection.autocommit">
${hibernate.connection.autocommit}
</prop>
<prop key="hibernate.proxool.xml">
${hibernate.proxool.xml.v4}
</prop>
<prop key="hibernate.proxool.pool_alias">
${hibernate.proxool.pool_alias.v4}
</prop>
</props>
</property>
</bean>
<!-- Transaction Annotation -->
<tx:annotation-driven transaction-manager="jtaTxManager"/>
<!-- Persistence Dao -->
<!-- V7 -->
<bean id="v7Dao" class="com.*.dao.V7DaoImpl"></bean>
<!-- V4 -->
<bean id="v4Dao" class="com.*.dao.V4DaoImpl">
<property name="sessionFactory" ref="sessionFactoryV4"></property>
</bean>
</beans>
jdbc.properties構成:
#Hibernate Definition
hibernate.dialect=org.hibernate.dialect.SQLServerDialect
hibernate.show_sql=true
hibernate.cache.provider_class=org.hibernate.cache.NoCacheProvider
hibernate.connection.release_mode=auto
hibernate.autoReconnect=true
hibernate.bytecode.use_reflection_optimizer=true
hibernate.connection.autocommit=true
hibernate.connection.provider_class=org.hibernate.connection.ProxoolConnectionProvider
hibernate.proxool.xml=com/*/resource/proxool.xml
hibernate.proxool.pool_alias=V7
hibernate.proxool.xml.v4=com/*/resource/proxool.v4.xml
hibernate.proxool.pool_alias.v4=V4
proxool.xml(proxool.v 4.xmlと同じ)構成:
<?xml version="1.0" encoding="UTF-8"?>
<something-else-entirely>
<proxool>
<alias>V7</alias>
<driver-url>jdbc:jtds:sqlserver://localhost:1433/test</driver-url>
<driver-class>net.sourceforge.jtds.jdbc.Driver</driver-class>
<driver-properties>
<property name="user" value="sa"/>
<property name="password" value=""/>
</driver-properties>
<prototype-count>3</prototype-count>
<house-keeping-sleep-time>90000</house-keeping-sleep-time>
<house-keeping-test-sql>select 1</house-keeping-test-sql>
<minimum-connection-count>3</minimum-connection-count>
<maximum-connection-count>30</maximum-connection-count>
<simultaneous-build-throttle>25</simultaneous-build-throttle>
<statistics>10s,1m,1d</statistics>
<statistics-log-level>Debug</statistics-log-level>
<trace>false</trace>
<verbose>true</verbose>
</proxool>
</something-else-entirely>