garg10may
garg10may

Reputation: 6179

Hibernate choose database name for entities

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

Upvotes: 0

Views: 1147

Answers (1)

garg10may
garg10may

Reputation: 6179

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")

Upvotes: 2

Related Questions