0

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.

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 (i.e. I can modify data in DB_X and DB_Y in one transaction).

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 (i.e. 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 (i.e. the same way the legacy code is accessing the DB using plain JDBC).

Is it achievable?

YannickDee
  • 11
  • 1
  • My gut reaction was you could just tell spring data jdbc that your table was called "DB_X.dbo.table1" and cross your fingers :-) – moilejter Sep 13 '22 at 06:23

1 Answers1

0

I think you would use the schema attribute on the Table definition. JPA Table Spec

MarkOfHall
  • 3,334
  • 1
  • 26
  • 30
  • `schema` is something different. I.e. in my question above, `dbo` is the `schema` (there can be multiple schemas in each of the databases), not to mention that I'd like to use Spring Data JDBC not JPA. – YannickDee Jan 14 '21 at 19:18