java - Migrate Hibernate managed C3P0 Pool to Spring Managed -


i'm spring(yfying) application uses hibernate + c3p0 connection pool. i'm using managed hibernate context specific reasons. i'm using utility class "hibernateutil" session handling. first migration spring creating applicationcontext , retrieving sessionfactory bean in hibernateutil replacing code used build sessionfactory. when create session factory bean old hibernate.cfg.xml in spring works expected:

<bean id="sessionfactory" class="org.springframework.orm.hibernate3.localsessionfactorybean">      <property name="configlocation" value="classpath:config/hibernate.cfg.xml"></property>    </bean> 

hibernate.cfg.xml

<hibernate-configuration>  <session-factory>  <property name="connection.username">user</property>     <property name="connection.url">jdbc:mysql://localhost:3306/mydb?zerodatetimebehavior=converttonull</property>     <property name="dialect">org.hibernate.dialect.mysql5dialect</property>     <property name="connection.password">pass</property>     <property name="connection.driver_class">com.mysql.jdbc.driver</property>     <property name="hibernate.max_fetch_depth">3</property>     <property name="hibernate.current_session_context_class">org.hibernate.context.managedsessioncontext</property>     <property name="hibernate.transaction.auto_close_session">false</property>       <property name="hibernate.cache.region.factory_class">          net.sf.ehcache.hibernate.singletonehcacheregionfactory</property>     <property name="hibernate.cache.use_query_cache">true</property>     <property name="hibernate.cache.use_second_level_cache">true</property>     <property name="hibernate.show_sql">true</property>     <property name="query.substitutions">true 1, false 0, yes 'y', no 'n'</property>      <!-- configuration pool via c3p0-->       <property name="connection.provider_class">org.hibernate.connection.c3p0connectionprovider</property>     <property name="connection.isolation">2</property>      <property name="hibernate.c3p0.acquire_increment">3</property>      <property name="hibernate.c3p0.idle_test_period">120</property> <!-- seconds -->      <property name="hibernate.c3p0.max_size">100</property>      <property name="hibernate.c3p0.max_statements">50</property>      <property name="hibernate.c3p0.min_size">3</property>      <property name="hibernate.c3p0.timeout">1800</property>       <!-- mapping files -->    ....... 

if externalize connection pool (i remove connection settings hibernate.cfg.xml), transactions not work properly.

<bean id="mydatasource" class="com.mchange.v2.c3p0.combopooleddatasource" destroy-method="close">      <property name="driverclass" value="${db.driver}"/>      <property name="jdbcurl" value="${db.url}"/>      <property name="user" value="${db.user}"/>      <property name="password" value="${db.pass}"/>    </bean>        <bean id="sessionfactory" class="org.springframework.orm.hibernate3.localsessionfactorybean">         <property name="datasource" ref="mydatasource"/>         <property name="configlocation" value="classpath:config/hibernate.cfg.xml"></property>        </bean> 

i've tried specifying hibernate.transaction.factory_class , moving hibernate properties spring bean configuration instead of using hibernate.cfg.xml no avail. cannot switch spring transaction management yet.

imho should try move spring. in experience when mixed there lot of problems. there particular reason why cannot yet set spring managed transaction management using:

<!-- transaction management -->     <tx:annotation-driven transaction-manager="txmanager" proxy-target-class="true"/>     <bean id="txmanager" class="org.springframework.orm.hibernate4.hibernatetransactionmanager">         <property name="sessionfactory" ref="sessionfactory" />     </bean> 

from description quite dificult find out problem occuring transactions or sessionfactory? point might causing sessionfactory problems when using datasource outside of hibernateproperties connectionprovider implementation hibernate using changing. if specify datasource hibernate use datasourceconnectionprovider(http://docs.jboss.org/hibernate/orm/3.6/javadocs/org/hibernate/connection/datasourceconnectionprovider.html) whereas setting data source in hibernate config hibernate use drivermanagerconnectionprovider (http://docs.jboss.org/hibernate/orm/3.2/api/org/hibernate/connection/drivermanagerconnectionprovider.html) differences between these 2 might cause of problems.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -