File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes How to mix JPA and JDBC transaction? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Application Frameworks » Spring
Reply Bookmark "How to mix JPA and JDBC transaction?" Watch "How to mix JPA and JDBC transaction?" New topic
Author

How to mix JPA and JDBC transaction?

Fernando Franzini
Ranch Hand

Joined: Jan 09, 2009
Posts: 302

Hi folks

I am desperately looking for information on how to configure the transaction org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport to be executed within the transaction org.springframework.orm.jpa.JpaTransactionManager.
I've tried to do what the documentation showed me but still did not work ..
Has anyone done or know of any tutorial?


Fernando Franzini - Java Blog
Fernando Franzini
Ranch Hand

Joined: Jan 09, 2009
Posts: 302

I just solve!!

In Class JpaTransactionManager say:
Note: To be able to register a DataSource's Connection for plain JDBC code, this instance needs to be aware of the DataSource (setDataSource(javax.sql.DataSource)). The given DataSource should obviously match the one used by the given EntityManagerFactory. This transaction manager will autodetect the DataSource used as known connection factory of the EntityManagerFactory, so you usually don't need to explicitly specify the "dataSource" property.

and you need create a special bean to mix transaction like this:

<bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"/>
<bean id="transacaoJPA" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="emf"/>
<property name="dataSource" ref="poolBean"/>
<property name="jpaDialect" ref="jpaDialect"/>
</bean>
See yaa
 
 
subject: How to mix JPA and JDBC transaction?
 
Threads others viewed
Hibernate Transaction - CMT
WA #1.....word association
Transaction in JDBC?
session.flush(); gives null
SCJP 1.5 Voucher sale for $220
IntelliJ Java IDE