1

In my hibernate configuration file i used to specify the properties including the database name

<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test</property>

in one of the hbm files

<class name="com.test.entity.User" table="user" catalog="employee">

Why the catalog in hbm files overrides the connection to the database specified in the hibernate configuration file hibernate ?

Does it connect to both databases?

techbrainless
  • 129
  • 2
  • 12

1 Answers1

0

The entity-level configuration overrides the default one because you might want to have a default catalog for most of your entities while only a few of those should be used against a different catalog.

Anyway the global catalog settings is:

<prop key="hibernate.default_catalog">employee</prop>

But in MySql, there's no difference between the database name in the JDBC URL and the database catalog object.

In your example, the User entity will use the employee catalog and not the test one.

Community
  • 1
  • 1
Vlad Mihalcea
  • 142,745
  • 71
  • 566
  • 911