Mapping tables in different databases via @Table annotation

fellow coders!

I have following problem:

I’m fetching data from database with @Table entities and everything is perfect, but now I have to connect to multiple databases and I would like to preserve @Table annotations.

I’ve seen some solutions for multi-database access (like this) but I don’t quite understand how to use @Table annotation with such solution. Is it somehow possible?


  1. Create separate packages for tables in each database.
  2. When defining the session factory, define the package of Tables related to the database.
  3. When defining DAO inject appropriate session factory to fetch the data.

Alternatively, define the annotated classes (the @Table classes are annotated classes) the in each session factory.

Leave a Reply

Your email address will not be published. Required fields are marked *