简体   繁体   English

Hibernate 5 模式验证:缺少带有 HBM 文件的表

[英]Hibernate 5 Schema-validation: missing table with HBM files

This problem is very similar to one I had before.这个问题与我之前遇到的问题非常相似。 I am converting an existing non-Spring application from Hibernate 3.x to the very latest 5.6.0.Final (at this time).我正在将现有的非 Spring 应用程序从 Hibernate 3.x 转换为最新的 5.6.0.Final(此时)。 We are using the MariaDB in AWS and are using the latest MariaDB Driver.我们在 AWS 中使用 MariaDB 并使用最新的 MariaDB 驱动程序。 We are also still using HBM xml files at this time for older tables until we move away from them.我们目前还在为旧表使用 HBM xml 文件,直到我们离开它们。

We do have an existing table in the database, I can absolutely confirm this.我们在数据库中确实有一个现有表,我可以绝对确认这一点。 The error is as follows:错误如下:

09:32:22.950> ERROR   PersistenceManager:123 Initial SessionFactory creation failed.
org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing table [my_db.commtemplateinfos]
at org.hibernate.tool.schema.internal.AbstractSchemaValidator.validateTable(AbstractSchemaValidator.java:121)
at org.hibernate.tool.schema.internal.GroupedSchemaValidatorImpl.validateTables(GroupedSchemaValidatorImpl.java:42)
at org.hibernate.tool.schema.internal.AbstractSchemaValidator.performValidation(AbstractSchemaValidator.java:89)
at org.hibernate.tool.schema.internal.AbstractSchemaValidator.doValidation(AbstractSchemaValidator.java:68)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:200)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:81)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:327)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:471)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:728)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:746)
at com.myproject.server.services.db.service.PersistenceManager.buildSessionFactory(PersistenceManager.java:504)

So, this error happens when we try to build the SessionFactory.因此,当我们尝试构建 SessionFactory 时会发生此错误。

I can also provide some of the configuration for this:我还可以为此提供一些配置:

<hibernate-configuration>
    <session-factory>

    <!-- Database connection settings -->
    <property name="connection.driver_class">org.mariadb.jdbc.Driver</property>
    <property name="connection.url">jdbc:mariadb://${mysql.host.name}:3306/${mysql.db.name}?characterEncoding=UTF-8&amp;serverTimezone=UTC</property>
    <property name="connection.username">${mysql.user.name}</property>
    <property name="connection.password"><![CDATA[${mysql.password}]]></property>
    
    <!-- Database Connection Limits -->
    <property name="initialSize">10</property>
    <property name="maxActive">15</property>
    <property name="maxWait">5000</property>
    <property name="maxIdle">1</property>
    <property name="hibernate.default_catalog">${mysql.db.name}</property>
    
    <!-- Naming Strategy -->
    <property name="hibernate.naming.physical-strategy">org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl</property>
    <property name="hibernate.naming.implicit-strategyy">org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl</property>

    <!-- SQL dialect -->
    <property name="hibernate.dialect">org.hibernate.dialect.MariaDB102Dialect</property>

    <!-- Enable Hibernate's automatic session context management -->
    <property name="hibernate.transaction.coordinator_class">org.hibernate.transaction.JDBCTransactionFactory</property>
    <property name="current_session_context_class">thread</property>

    <!-- Configure the second-level cache  -->
    <property name="hibernate.cache.ehcache.missing_cache_strategy">create</property>
    <property name="hibernate.cache.use_second_level_cache">true</property>
    <property name="hibernate.cache.region.factory_class">org.hibernate.cache.jcache.JCacheRegionFactory</property>
    <property name="hibernate.javax.cache.provider">org.ehcache.jsr107.EhcacheCachingProvider</property>

    <!-- Echo all executed SQL to stdout -->
    <property name="show_sql">${hibernate.show.sql}</property>

    <!-- Update the database schema on startup -->
    <property name="hbm2ddl.auto">validate</property>

    <!-- Configure the connection Pool for Hibernate -->
    <property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>

... mappings here ...
<mapping resource="com/myproject/server/model/Project.hbm.xml"/>

    </session-factory>
</hibernate-configuration>

I tried the naming strategy based on some other posts here, but they didn't do anything.我尝试了基于此处其他一些帖子的命名策略,但他们什么也没做。

Here is the definition of this 'list' within the Project.hbm.xml:这是 Project.hbm.xml 中此“列表”的定义:

<list name="commTemplateInfos" table="commtemplateinfos" cascade="all, delete-orphan" lazy="false">
    <key column="projectId" not-null="false" />
    <list-index column="listIndex" />
    <composite-element class="com.myproject.server.model.CommTemplateInfo" >
        <property name="name"   not-null="false" />
        <property name="frequency"   not-null="false" />
    </composite-element>
</list>

I think I've provided everything I need to provide.我想我已经提供了我需要提供的一切。 I have tried a lot of things based on similar posts here on StackOverflow, and no luck.我已经根据 StackOverflow 上的类似帖子尝试了很多东西,但没有成功。 The worst part is that when I run my unit tests I do not get this error locally.最糟糕的是,当我运行单元测试时,我不会在本地遇到此错误。 It only happens when I run this against our TeamCity which uses another database.只有当我针对使用另一个数据库的 TeamCity 运行它时才会发生。 It is still a MariaDB there, and yes, the table really does actually exist in that database, so no, that's not the issue.它仍然是 MariaDB,是的,该表确实确实存在于该数据库中,所以不,这不是问题所在。

I am sure this is a minor configuration issue from the legacy HBM xml files.我确信这是遗留 HBM xml 文件中的一个小配置问题。 I honestly cannot wait until we go to proper annotated classes.老实说,我不能等到我们 go 到正确的注释类。 In the meantime, there has got to be a simple solution to fix this.与此同时,必须有一个简单的解决方案来解决这个问题。

Well, I now know what happened, and this has to do with some craziness in Hibernate 5 and database table names.好吧,我现在知道发生了什么,这与 Hibernate 5 和数据库表名中的一些疯狂行为有关。 The actual table name in the databases was: commTemplateInfos.数据库中的实际表名是:commTemplateInfos。

When I ran my unit test locally against my local database (MariaDB), it was NOT case-sensitive for the table names.当我在本地针对本地数据库 (MariaDB) 运行单元测试时,表名不区分大小写。 However, our database that TC uses IS very much case-sensitive and as a result would not find the table at all.然而,我们 TC 使用的数据库非常区分大小写,因此根本找不到该表。

The solution was pretty simple, rename the table to: comm_template_info So, we space out with an underscore (_) but also made it singular to match all the other table names.解决方案非常简单,将表重命名为: comm_template_info 因此,我们用下划线 (_) 隔开,但也将其设为单数以匹配所有其他表名。 Once we did this, our hbm.xml file was changed to match this exact table name and our problem went away.一旦我们这样做了,我们的 hbm.xml 文件被更改为匹配这个确切的表名,我们的问题就消失了。

I hope this helps someone else out.我希望这可以帮助其他人。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java Spring Hibernate Schema-Validation:缺少表 - Java Spring Hibernate Schema-Validation: Missing Table 架构验证:缺少表 [hibernate_sequences] - Schema-validation: missing table [hibernate_sequences] Hibernate + JPA:模式验证:缺少列 - Hibernate + JPA: Schema-validation: missing column Hibernate继承:模式验证:缺少列 - Hibernate inheritance: Schema-validation: missing column 使用Schema-validation验证除dbo结果以外的其他模式中的休眠访问表:缺少表 - Hibernate acessing table in schema other than dbo results with Schema-validation: missing table Hibernate:模式验证:缺少表 - 区分大小写 Mysql 模式标识符变为大写 - Hibernate: Schema-validation: missing table - case-sensitive Mysql schema identifier turned upper-case SqlServer2016,Hibernate 模式验证:缺少表,但表存在于数据库中 - SqlServer2016, Hibernate schema-validation: Missing table, but table exists in db 模式验证:使用Flyway的Hibernate生成的SQL代码缺少表[…]错误消息 - Schema-validation: missing table […] error message using flyway for a SQL code generated by Hibernate 获取 entityManageFactory 错误。 模式验证:缺少表 [hibernate_sequence] - Getting entityManageFactory error. Schema-validation: missing table [hibernate_sequence] Spring Boot 项目由于 Schema-validation 无法运行:缺少序列 [hibernate_sequence] - Spring Boot project fails to run because of Schema-validation: missing sequence [hibernate_sequence]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM