0

I have MySql backend to my spring boot application. I have segregated db tables in different schemas. I wish to address the tables from different schemas as my hibernate entities. However, I am able to access just one schema, which is mentioned along with my connection URL in applications.properties. Also, using @Table(schema="mySchema", name="tbl1") will not give expected results. This is not an issue with Postgres database engine as in PostgreSQL, schema and databases have a different meaning altogether. Is there any workaround problem for this?

pMate28
  • 11
  • 2
  • Have you tried `name="myschema.tbl1"`? In mysql databasename.tablename format allows you to access a table in another database (schema) on the same server instance. – Shadow Nov 05 '18 at 00:16
  • I was able to solve my problem. It was a confusion caused by the terminologies. If you are using mysql backend, u will need to use catalog property in @Table annotation @Table(name="tbl_name", catalog="schema_name") instead of schema property – pMate28 Nov 08 '18 at 18:32

2 Answers2

1

You will need to configure datasource for each of those schemas, as schemas are synonymous to databases in mySQL. This stackoverflow answer https://stackoverflow.com/a/45665826/5107365 details how to configure multiple jpa repositories to work with multiple datasources in Spring Boot environment. Please check.

Raj
  • 778
  • 1
  • 10
  • 14
1

I tried using catalog property in @Table annotation and it worked.

pMate28
  • 11
  • 2