1

I have a spring boot application that uses spring data jdbc and connects to two databases. One of them is postgres and one is oracle. I access them via jdbc repositories (org.springframework.data.repository.Repository).

That works very well in general but all the repositories use the same dialect. How can I use different jdbc dialects based on the jdbc repository that is used for the query?

mio
  • 562
  • 5
  • 19

1 Answers1

2

Maybe this helps someone else in the future:

It is possible to implement your own version of JdbcRepositoryFactoryBean and hard code the Dialect there. The custom class can then be used with the @EnableJdbcRepositories annotation.

Example configuration for an oracle database:

@EnableJdbcRepositories(basePackageClasses = my.oracle.DbRepository.class,
  jdbcOperationsRef = "secondaryNamedParameterJdbcTemplate",
  transactionManagerRef = "secondaryTransactionManager",
  repositoryFactoryBeanClass = OracleRepositoryFactoryBean.class)

Example of custom factory bean:

public class OracleRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extends Serializable>
extends JdbcRepositoryFactoryBean<T, S, ID> {
   // override constructor and set dialect
   // override setDialect to be safe
}

If there is a more elegant solution please add it.

mio
  • 562
  • 5
  • 19