简体   繁体   English

如何在同一 MS SQL 服务器实例上跨多个数据库使用 Spring 数据 JDBC?

[英]How to use Spring Data JDBC across multiple databases on the same MS SQL Server instance?

I've inherited a legacy app with a massive MSSQL database instance where data model is spread across multiple databases on the same SQL Server instance.我继承了一个带有大型 MSSQL 数据库实例的遗留应用程序,其中数据 model 分布在同一个 SQL 服务器实例上的多个数据库中。

In T/SQL you can normally run queries (even joins) across databases on the same instance ( SELECT... FROM DB_X.dbo.table1 JOIN DB_Y.dbo.table2 ON... ) and the transactions also work as expected (ie I can modify data in DB_X and DB_Y in one transaction).在 T/SQL 中,您通常可以跨同一实例上的数据库运行查询(甚至连接)( SELECT... FROM DB_X.dbo.table1 JOIN DB_Y.dbo.table2 ON... )并且事务也按预期工作(即我可以在一个事务中修改 DB_X 和 DB_Y 中的数据)。

I'd like to write a new Java program that accesses the data model using Spring Data JDBC but I can't find a way how to map entities to tables in different databases. I'd like to write a new Java program that accesses the data model using Spring Data JDBC but I can't find a way how to map entities to tables in different databases.

I've found articles how to connect to multiple databases but they involve defining multiple connections and separate transactions (ie they are really meant for multiple databases as in different instances or even different database types).我找到了如何连接到多个数据库的文章,但它们涉及定义多个连接和单独的事务(即它们实际上适用于不同实例甚至不同数据库类型中的多个数据库)。

However, I'd just like to use one connection and single transaction (ie the same way the legacy code is accessing the DB using plain JDBC).但是,我只想使用一个连接和单个事务(即,与旧代码使用普通 JDBC 访问数据库的方式相同)。

Is it achievable?它可以实现吗?

I think you would use the schema attribute on the Table definition.我认为您会在Table定义中使用schema属性。 JPA Table Spec JPA表规格

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用jdbc查询两个数据库到sql服务器的同一实例 - using jdbc to query two databases to the same instance of sql server 如何在 sql 服务器中配置多个目录/数据库,这些目录/数据库位于 spring 启动 java 8 应用程序中的同一数据库服务器上? - How to configure multiple catalogs/databases in sql server which are on same database server in spring boot java 8 app? 如何使用JDBC连接单个服务器上的多个数据库? - how to connect multiple databases on a single server with JDBC? 如何在Java Spring中的不同请求中使用SET的相同实例 - How to use the same instance of a SET across different requests in Java Spring JDBC 未将数据插入 MS SQL 服务器 - JDBC not inserting data into MS SQL Server 如何在spring中使用多个数据库? - How to use multiple databases with spring? Spring Boot:使用dblink在多个数据库中对同一实体建模 - Spring Boot: modeling same entity across multiple databases with dblink 如何在MS SQL Server 2008 Express中使用MS JDBC驱动程序? - How can I use the MS JDBC driver with MS SQL Server 2008 Express? Springboot + Spring数据在多个数据库中同一个实体 - Springboot + Spring data same entity in multiple databases 如何在 Spring 启动 jdbc 应用程序中配置 2 个数据库并将数据插入表中 - How to configure 2 databases in Spring boot jdbc application and insert data into table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM