spring-projects / spring-projects/spring-data-examples
MutiTenant Db is not working when using two different databases
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 5.4k
- Forks
- 3.4k
- PR merge metrics
- No merged PRs in 30d
Description
The current sample provided in this repo is working as long as database type is same like here where both databases are of type postgresql
When I tried to move one database configuration to another database say mariadb, as its dialect is different receiving syntax errors while saving the data like below
2025-01-22T22:42:07.860+05:30 ERROR 39800 --- [multitenancy-db] [omcat-handler-0] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet [(conn=103) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''public.customers_seq')' at line 1] [select nextval('public.customers_seq')]; SQL [select nextval('public.customers_seq')]] with root cause
Use case here is till 2024 customer has used mariadb and now they are moving to postgresql. They want to migrate to postgresql gradually so as of now based on some business logic they want to query mariadb and postgresql as per outcome.
How to set different databases using same entity and same repository?
cc : @schauder
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the jpa/multitenancy/multitenancy-db sample linked in the issue and reproduce the failure using PostgreSQL and MariaDB configurations. Trace the generated sequence SQL and the shared entity/repository setup. Done means the same entity and repository can route queries to both database types without dialect-specific SQL errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, mariadb, postgresql, spring-boot
- Domain
- backend, databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100