springspring-data-jpaweblogic12cspring-orm

Issue in using Spring Data JPA with Spring JPA


Issue
- Getting a war file deployment error. Getting runtime exception. Error details are mentioned after some additional information.

Some background -
1) Functionality was working with Spring JPA library. When it is migrated to Spring Data JPA it is failing.
2) I am using Spring Java annotation based configuration to load beans.
3) I am having 2 datasources. One of this is using datasource to access data which can be retrieved using different jar file. This jar file is using Spring Data JPA v 1.10.2.RELEASE
4) Our application is using Spring 4.2.6 version

Implementation -

@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(basePackages = 
"com.security.repository", entityManagerFactoryRef = 
"entityManager")
public class PersistenceConfig {

    @Bean(name = "dataSource")
    public DataSource dataSource() throws NamingException {
        return (DataSource) jndidataSource().getObject();
    }

    @Bean
    public JndiObjectFactoryBean jndiDataSource() {
     JndiObjectFactoryBean jndiObjectFactoryBean = new 
     JndiObjectFactoryBean();
     jndiObjectFactoryBean.setJndiName("dbDataSourceName");
     jndiObjectFactoryBean.setExpectedType(DataSource.class);
     return jndiObjectFactoryBean;
   }

     @Bean(name = "entityManager")
     public LocalContainerEntityManagerFactoryBean entityManagerObj() throws 
     NamingException {
    LocalContainerEntityManagerFactoryBean emf = new 
      LocalContainerEntityManagerFactoryBean();
    emf.setJtaDataSource(jndiDataSource());
    emf.setPersistenceUnitName("PersistenceUnit");
    emf.setPackagesToScan("com.security.entity");
    emf.setLoadTimeWeaver(new InstrumentationLoadTimeWeaver());
    emf.setPersistenceProvider(new PersistenceProvider());
    emf.setJpaProperties(getJPAProperties());
    return emf;
  }

  private Properties getJPAProperties() {
    Properties jpaProperties = new Properties();
    jpaProperties.put("eclipselink.weaving", "false");
    jpaProperties.put("eclipselink.jpa.uppercase-column-names", "true");
    jpaProperties.put("eclipselink.logging.level", "SEVERE");
    jpaProperties.put("eclipselink.logging.parameters", "true");
    jpaProperties.put("eclipselink.query-results-cache", "false");
    jpaProperties.put("eclipselink.cache.shared.default", "false");
    jpaProperties.put("eclipselink.cache.type.default ", "NONE");
    jpaProperties.put("eclipselink.logging.level.sql", "SEVERE");
    jpaProperties.put("eclipselink.jdbc.batch-writing", "JDBC");
    jpaProperties.put("eclipselink.jdbc.batch-writing.size", "100");
    return jpaProperties;
 }
}

When an application is deployed with the above configuration it is giving me below error. Not sure what is missing or incorrect. Since it was working with library implemented with Spring JPA and not Spring Data JPA. Please suggest -

org.springframework.beans.factory.UnsatisfiedDependencyException: Error 
creating bean with name 'jpaContext': Unsatisfied dependency expressed 
through constructor argument with index 0 of type [java.util.Set]: Error 
creating bean with name 
'org.springframework.orm.jpa.SharedEntityManagerCreator#2': Unsatisfied 
dependency expressed through constructor argument with index 0 of type 
[javax.persistence.EntityManagerFactory]: Could not convert factory method 
argument value of type [weblogic.jdbc.common.internal.RmiDataSource] to 
required type [javax.persistence.EntityManagerFactory]: Failed to convert 
value of type [weblogic.jdbc.common.internal.RmiDataSource] to required type 
[javax.persistence.EntityManagerFactory]; nested exception is 
java.lang.IllegalStateException: Cannot convert value of type 
[weblogic.jdbc.common.internal.RmiDataSource] to required type 
[javax.persistence.EntityManagerFactory]: no matching editors or conversion 
strategy found; nested exception is 
org.springframework.beans.factory.UnsatisfiedDependencyException: Error 
creating bean with name 
'org.springframework.orm.jpa.SharedEntityManagerCreator#2': Unsatisfied 
dependency expressed through constructor argument with index 0 of type 
[javax.persistence.EntityManagerFactory]: Could not convert factory method 
argument value of type [weblogic.jdbc.common.internal.RmiDataSource] to 
required type [javax.persistence.EntityManagerFactory]: Failed to convert 
value of type [weblogic.jdbc.common.internal.RmiDataSource] to required type 
[javax.persistence.EntityManagerFactory]; nested exception is 
java.lang.IllegalStateException: Cannot convert value of type 
[weblogic.jdbc.common.internal.RmiDataSource] to required type 
[javax.persistence.EntityManagerFactory]: no matching editors or conversion 
strategy found

Solution

  • This got resolved by moving from Java based bean configuration to XML based configuration.