3

I have a legacy project which was using Spring 3.0.x and made use of the JpaTemplate implementation provided by Spring.

However, after upgrading to Spring 4.0.x I learned that JpaTemplate was deprecated as of Spring 3.2

I have seen suggestions to simply refactor out the use of JpaTemplate with EntityManager.

However, replacing JpaTemplate with EntityManager is not sufficient as I discovered this project was wrapping the JpaTemplate calls in a JpaCallback, which in turn used entitymanager. I imagine the reason callbacks were used was to allow these DAO calls to be ran asynchronously.

Are there any suggested recommendations on how to refactor applications which make use of JpaTemplate and the JpaCallback class when upgrading to Spring 4?

M. Deinum
  • 115,695
  • 22
  • 220
  • 224
Adam Bronfin
  • 1,209
  • 3
  • 27
  • 43
  • Related: http://stackoverflow.com/questions/31925138/how-to-migrate-usage-of-jpatemplate-from-spring-3-2-to-4-1-4 –  Feb 01 '16 at 06:07
  • 1
    If it is a `JpaCallback` it is quite easy to replace that with an entity manager, just re move the wrapping code. The `JpaCallback` doesn't wrap the template it is the other way around. One thing you might now find is that you have an issue with transactions, and that is basically a sign of having a wrong transaction setup in the first place. – M. Deinum Feb 01 '16 at 06:53

1 Answers1

2

Additionally to replacing JPATemplate, you should enable annotation configuration using <context:annotation-config /> or configure a PersistenceAnnotationBeanPostProcessor to enable the injection of the EntityManager into the DAOs. If you have <context:component-scan /> activated, you should be fine to use all the features as it was before migration.

m.aibin
  • 3,528
  • 4
  • 28
  • 47