Meaningless Drivel is fun!*
The moose likes Spring and the fly likes How to mix JPA and JDBC transaction? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Spring
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: 486
    
    2

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: 486
    
    2

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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to mix JPA and JDBC transaction?
 
Similar Threads
Transaction in JDBC?
Hibernate Transaction - CMT
SCJP 1.5 Voucher sale for $220
WA #1.....word association
session.flush(); gives null