0

As you must be aware in MySQL namespaces and database are essentially the same thing.

How can I tell hibernate to use a particular db for an Entity. It by default uses the one defined in the spring.datasource.url. So here it would be looking entities in db1 database.

spring.datasource.url=jdbc:mysql://localhost:3306/db1

If I use @Table(name= db2.sample_table) it looks for db1.db2_sample_table

garg10may
  • 5,794
  • 11
  • 50
  • 91
  • The `@Table` annotation has a `schema` property. `@Table(name = "sample_table", schema="db2")` should be sufficient. – manish Jun 11 '19 at 08:32
  • this doesn't seem to be working, it's ignoring the schema and looking in default schema only. – garg10may Jun 11 '19 at 08:42
  • As your question has been viewed 11 times now it might have been anyone else who voted on your question. I don't see a reason to close this. BTW: You may accept your own answer. – Selaron Jun 11 '19 at 11:00

1 Answers1

2

Apparently, there seems to be a bug in Hibernate 5.0+ and MySql and using schema syntax doesn't work because MySql considers both schema and database same

@Table(name="some_table", schema="db2")

instead one can use catalog instead of schema.

@Table(name="some_table", catalog="db2")
garg10may
  • 5,794
  • 11
  • 50
  • 91