Testing with miltiple databases #1289
Labels
in: jdbc
Spring Data JDBC
status: duplicate
A duplicate of another issue
status: waiting-for-triage
An issue we've not yet triaged
Hello everyone!
I have a project that need to use several databases for tests.
I want to autowire different repositories that uses different databases connections in one test, for example:
But I can't implement it using spring-data-jdbc, it allows me two use only one database connection.
I prepare a sample project to better understanding the situation and you can try by yourself, but you have to run your own two databases.
There are tree gradle modules: module for first database, module for second database and module for tests.
root module
|- first-db-client
|- second-db-client
|- tests
First two modules I want to use as two separate dependencies in future.
Here is my root
build.gradle
file.tests module depends on two databases modules:
Let's take a look at first-db-client.
It has a simple entity, repository for it and configuration class.
second-db-client has the similar structure except it has different entity and repository and another DataSource bean.
When I run the test it successfuly execute only first query and second one fails with an error with message something like this:
PreparedStatementCallback; bad SQL grammar [ sql query ]; nested exception is org.postgresql.util.PSQLException: ERROR: relation 'table name' does not exist
It means that both repositories uses the same database connection and this is the problem I'm trying to solve.
As you can see I'm trying to use
@Qualifier
annotation, specific bean names, overridingAbstractJdbcConfiguration
beans to separate two connections, all my tries is there, but nothing is working.What I'm doing wrong? How can I implement this case? Is it possible?
If not it would cool feature.
Can you please help?
PS: I don't want to use spring-data-jpa, because it is too heavy and has too much functionality for my needs. I don't want to use
JdbcTemplate
, because I want to usePagingAndSortingRepository
sugar not to write simple queries. And sory for my English, it's not my native language.The text was updated successfully, but these errors were encountered: