Skip to content

Dynamic MappedStatement with dynamic databaseId #3429

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Terrdi
Copy link

@Terrdi Terrdi commented Mar 13, 2025

initialize all of the statements which is marked datasourceId when configuration set supportDynamicRoutingDataSource.

The databaseIdProvider provide current databaseid for statement match.

@Terrdi Terrdi force-pushed the feature/dynamic-datasource-support branch 3 times, most recently from 6a59687 to b466fc0 Compare March 14, 2025 04:05
@harawata
Copy link
Member

Hello @Terrdi ,

If this is about switching the databaseId while the application is running, it may require major design change.

Could you explain the use case?
I am curious why people need this.

…nfiguration set supportDynamicRoutingDataSource. The databaseIdProvider provide current databaseid for statement match.
@Terrdi Terrdi force-pushed the feature/dynamic-datasource-support branch from b466fc0 to 5589317 Compare March 14, 2025 19:15
@Terrdi
Copy link
Author

Terrdi commented Mar 14, 2025

I hope to support multiple data sources (different interfaces access different types of databases) instead of just one type of database.

@harawata
Copy link
Member

In that case, you should create multiple SqlSessionFactory instances (e.g. factory 1 for Oracle and factory 2 for MySQL) and add mappers used in each DB (e.g. add mapper A and B to factory 1; add mapper C, D and E to factory 2).
Search "mybatis multiple datasource" and you'll find many articles/examples.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants