-
Jul 25th, 2012, 01:17 AM
#1
Sharing connection between plain jdbc and jpa entity manager
I'm using JPATransactionMaanger and single datasource where in we are using hibernate and Spring for new entity model and we have old data service layer where in it uses plain jdbc code. We donot have any option to change this code since its owned by third party product vendor.
I'm programatically handling transaction using JPATransactionManager inorder to support legacy and hibernate data layer.
I'm not able to share the same connection between plain JDBC code and JPATransactionManager. I'm using same datasource to get the connection and passed to the legacy application code whenever its needed.
here is the sample xml configuration.
into Spring's generic DataAccessException hierarchy -->
<bean
class="org.springframework.dao.annotation.Persiste nceExceptionTranslationPostProcessor" />
<bean id="db2dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${database.db2.driverClassName}" />
<property name="url" value="${database.db2.url}" />
<property name="username" value="${database.db2.username}" />
<property name="password" value="${database.db2.password}" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<!-- the transactional advice (i.e. what 'happens'; see the <aop:advisor/> bean below)
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop
ointcut id="erepServiceOperation" expression="execution(* gov.utah.erep.service*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="erepServiceOperation"/>
</aop:config>
-->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionM anager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
<property name="jpaDialect" ref="jpaDialect" />
<property name="dataSource" ref="db2dataSource"></property>
</bean>
<bean id="jpaDialect"
class="gov.utah.erep.dataservice.util.HibernateExt endedJpaDialect" />
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerE ntityManagerFactoryBean">
<property name="dataSource" ref="db2dataSource" />
<property name="persistenceXmlLocation" value="META-INF/persistence.xml"></property>
<property name="persistenceUnitPostProcessors">
<list>
<ref bean="entityScanner" />
</list>
</property>
</bean>
Please help me out to resolve the issue ... JDBC Connection are accessed using DataSourceUtils.getConnection(DataSource) -> Datasource is same as the one which has been used in entityManagerFactory.
I'm using programatic transaction handling rather than using annotation since I'm extending the method which is already exists in legacy code ( begin , commit, rollback , getConnection) and using JpATransactionManager
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules