5

We currently have Spring 3.2.9.RELEASE configured and running (for a couples of years) and need to migrate to 4.1.4.RELEASE. We have an abstract DAO class that extends org.springframework.orm.jpa.support.JpaDaoSupport as well as other references to:

  • org.springframework.orm.jpa.JpaCallback
  • org.springframework.orm.jpa.JpaTemplate

I've seen that JpaDaoSupport has been removed in Spring 4. I've removed references to the Jpa* classes and replaced with

@PersistenceContext 
protected EntityManager theEntityManager;

and for method references in our DAO (like findByNamedParams()) found in JpaDaoSupport, and copied into our DAO.

After the above changes, we are able to compile our code but when it comes to running our JUnit tests, there is a reference in our applicationContext-test.xml of

<bean id="jpaTemplate" class="org.springframework.orm.jpa.JpaTemplate">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

<bean id="abstractDAO" abstract="true" class="my.company.package.AbstractDAO">
    <property name="jpaTemplate" ref="jpaTemplate" />
</bean>

<bean id="genericDAO" parent="abstractDAO" class="my.company.package.GenericDAO" />
<bean id="securityDAO" parent="abstractDAO" class="my.company.package.SecurityDAOImpl" />

Basically the error is there is no class reference of org.springframework.orm.jpa.JpaTemplate. How do we replace this JpaTemplate configuration for Spring 4.1.4?

Note that I'm picking this code up and wasn't the one who initially configured the system. Also I'm pretty new to Spring and its configuration setup.

Oliver Drotbohm
  • 80,157
  • 18
  • 225
  • 211
Jim Athrs
  • 61
  • 1
  • 3

1 Answers1

2
  1. Make sure AbstractDAO is migrated to the EntityManager API and uses @PersistenceContext on an injection point (a setter usually).
  2. Enable annotation configuration using <context:annotation-config /> or configure a PersistenceAnnotationBeanPostProcessor to enable the injection of the EntityManager into the DAOs. You can get rid of the bean definition for AbstractDAO entirely. Note, that if you have <context:component-scan /> activated somewhere, this should already work out of the box.

PS: You might wanna consider to upgrade to Spring 4.2 right away if you're migrating anyway. If that's not an option, please go with the latest Spring 4.1 version (4.1.7 at the time of writing).

Oliver Drotbohm
  • 80,157
  • 18
  • 225
  • 211
  • Sorry for the delay in replying. Here are the changes:The jpaTemplate is removed in the above reference. The abstractDAO above does not have property reference. We are able to get past the junit test. During our WL 12c startup, we're now getting the following exception: Caused By: java.lang.ClassCastException: net.sf.ehcache.store.compound.ReadWriteSerializationCopyStrategy cannot be cast to net.sf.ehcache.store.compound.ReadWriteCopyStrategy There are other springframework exceptions before this one but i can't paste them here due to lack of space. – Jim Athrs Aug 18 '15 at 12:16
  • The exception of the one here is Caused By: java.lang.RuntimeException: ReadWriteSerializationCopyStrategy doesn't implement net.sf.ehcache.store.compound.CopyStrategy – Jim Athrs Aug 18 '15 at 12:44