[英]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.