HIbernate 不会创建已经存在于另一个数据库中的 table

HIbernate doesn't create table that already exist in another database

我有一个名为 com.test.Student 的 bean 实体,它使用 xml 映射到出勤数据库中名为 "student" 的 table。 "student" table 考勤数据库还不存在。

Hibernate 不会在应用程序启动时创建 "student" table 考勤数据库,即使 属性 hibernate.hbm2dll.auto 设置为 "update"。它也不会生成任何异常、警告或查询。它根本不做任何事情。

经过一些测试,我开始意识到一个学生 table 已经存在于另一个名为 "sms" 的数据库中。如果我将 com.test.Student @Entity 映射到另一个 table 名称(在任何数据库中都不存在),Hibernate 将使用此配置创建它。

为什么 Hibernate 不在映射的数据库上创建 "student" table?另一个数据库中同名的 table 是否存在某种方式的干扰?

一些信息:

如评论部分所述,如果由于 table 模式之间的名称冲突,hibernate 未在 ddl auto 上创建 tables,您应该明确声明:

@Table(name="attendance.student")

这样 hibernate 就会正确地创建 table。如果那里没有显式声明架构,它将公开查找具有相同名称的其他 table,因此不会创建新架构。

看看this bug description。如果你想知道更多关于 hibernate 在创建新的 table 时的行为的细节,你一定要创建另一个 post 更简洁的场景,以便我们可以进一步讨论它。