for me it was the dialect and the jpavendor configuration
import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.JpaVendorAdapter;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(
basePackages = "com.xyz.Inquery.db.repo.oracle",
entityManagerFactoryRef = "oracleEntityManagerFactory",
transactionManagerRef = "oracleTransactionManager"
)
public class OracleConfig {
@Bean(name = "oracleDataSource")
@ConfigurationProperties(prefix = "spring.datasource.oracle")
public DataSource dataSource() {
return DataSourceBuilder.create().build();
}
@Bean(name = "oracleEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean entityManagerFactory(
EntityManagerFactoryBuilder builder,
@Qualifier("oracleDataSource") DataSource dataSource) {
LocalContainerEntityManagerFactoryBean em = builder
.dataSource(dataSource)
.packages("com.xyz.Inquery.oracle.entity")
.persistenceUnit("oracle")
.build();
// Customize the JpaVendorAdapter
em.setJpaVendorAdapter(jpaVendorAdapter());
return em;
}
@Bean
public JpaVendorAdapter jpaVendorAdapter() {
HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
adapter.setShowSql(true); // Set to true to log SQL queries
adapter.setGenerateDdl(true); // Set to true to generate DDL statements
adapter.setDatabasePlatform("org.hibernate.dialect.Oracle10gDialect"); // Specify the correct dialect this helped me
return adapter;
}
@Bean(name = "oracleTransactionManager")
public PlatformTransactionManager transactionManager(
@Qualifier("oracleEntityManagerFactory") EntityManagerFactory entityManagerFactory) {
return new JpaTransactionManager(entityManagerFactory);
}
}
and the postgres as
import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(
basePackages = "com.xyz.Inquery.db.repo.postgres",
entityManagerFactoryRef = "postgresEntityManagerFactory",
transactionManagerRef = "postgresTransactionManager"
)
public class PostgresConfig {
@Primary
@Bean(name = "postgresDataSource")
@ConfigurationProperties(prefix = "spring.datasource.postgres")
public DataSource dataSource() {
return DataSourceBuilder.create().build();
}
@Primary
@Bean(name = "postgresEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean entityManagerFactory(
EntityManagerFactoryBuilder builder,
@Qualifier("postgresDataSource") DataSource dataSource) {
return builder
.dataSource(dataSource)
.packages("com.xyz.Inquery.postgres.entity")
.persistenceUnit("postgres")
.build();
}
@Primary
@Bean(name = "postgresTransactionManager")
public PlatformTransactionManager transactionManager(
@Qualifier("postgresEntityManagerFactory") EntityManagerFactory entityManagerFactory) {
return new JpaTransactionManager(entityManagerFactory);
}
}
earlier i had missed out the em.setJpaVendorAdapter(jpaVendorAdapter()); part and the setDatabasePlatform part
finally my pom dependency looks like as below :
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Spring Boot Starter Web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Spring Boot Starter Data JPA -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- PostgreSQL Driver -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc8</artifactId>
<version>12.2.0.1.0</version>
</dependency>
</dependencies>
with application prop as following
spring.datasource.postgres.url=jdbc:postgresql://xyz/nsdl_insta_dmat
spring.datasource.postgres.username=abc
spring.datasource.postgres.password=abc
spring.datasource.postgres.driver-class-name=org.postgresql.Driver
spring.datasource.postgres.remove-abandoned=true
spring.datasource.postgres.initialSize=20
spring.datasource.postgres.maxActive=20
#oracle configuration
spring.datasource.oracle.jdbcUrl=jdbc:oracle:thin:@ip:port/AGG
spring.datasource.oracle.url=jdbc:oracle:thin:@ip:port/AGG
spring.datasource.oracle.username=avg
spring.datasource.oracle.password=abc
spring.datasource.oracle.driver-class-name=oracle.jdbc.OracleDriver
spring.datasource.oracle.default-schema=yourwish
I realized without configuring jpavendor it was throwing exception of jdbcurl. Hope this might help someone.