【问题标题】:why database name in hbm file overrides database name in hibernate configuration file为什么 hbm 文件中的数据库名称会覆盖休眠配置文件中的数据库名称
【发布时间】:2014-12-09 19:49:02
【问题描述】:

在我的休眠配置文件中,我曾经指定包括数据库名称在内的属性

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

在其中一个 hbm 文件中

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

为什么hbm文件中的目录会覆盖hibernate配置文件hibernate中指定的数据库连接?

它是否连接到两个数据库?

【问题讨论】:

    标签: hibernate


    【解决方案1】:

    实体级配置会覆盖默认配置,因为您可能希望为大多数实体拥有一个默认目录,而只有少数实体应该用于不同的目录。

    无论如何,全局编录设置是:

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

    但在 MySql 中,JDBC URL 中的数据库名称与数据库目录对象之间存在there's no difference

    在您的示例中,用户实体将使用员工 catalog 而不是 test

    【讨论】:

      猜你喜欢
      • 2021-03-11
      • 1970-01-01
      • 2013-03-31
      • 2018-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-28
      • 1970-01-01
      相关资源
      最近更新 更多