Spring JPA and JOOQ with Transacitonal Annotations

663 views
Skip to first unread message

Robert DiFalco

unread,
Jan 8, 2015, 4:22:58 PM1/8/15
to jooq...@googlegroups.com
Unless I'm missing something it appears that you can make JOOQ and JPA coexist with @Transactional if you make the following changes to the example in GitHUB.


1. In SpringTransactionProvider.java change the injected tx from DataSourceTransactionManager to PlatformTransactionManager (it's the interface DataSourceTransactionManager implements).
2. In Application.java replace the following method:

@Bean
public DataSourceTransactionManager transactionManager(DataSource dataSource) {
    return new DataSourceTransactionManager(dataSource);
}

With:

@Bean
public PlatformTransactionManager transactionManager() {
     return new JpaTransactionManager(entityManagerFactory().getObject());
}

The EntityManagerFactory should already be defined in your config. That's pretty much it. Since the EntityManager has your dataSource already it should allow the two to coexist with transactions. 

This should make it easier to migrate from JPA to JOOQ incrementally.

Let me know if I've missed anything. 

R.


Lukas Eder

unread,
Jan 9, 2015, 1:49:36 AM1/9/15
to jooq...@googlegroups.com
Hello,

Many of our users do use jOOQ and JPA within the same application. Using the two within the same transactions will work with the usual caveats of JPA implementations being unaware of changes made to the database that should affect the second-level cache.

Apart from this expected caveat, I suspect that your approach will be OK, although, I'm not sure what this getObject() method is on your EntityManagerFactory.

I've added an issue to document this in new examples:

--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages