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). We are using the MariaDB in AWS and are using the latest MariaDB Driver. We are also still using HBM xml files at this time for older tables until we move away from them.
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.
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&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:
<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. 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. It is still a MariaDB there, and yes, the table really does actually exist in that database, so no, that's not the issue.
I am sure this is a minor configuration issue from the legacy HBM xml files. I honestly cannot wait until we go to proper annotated classes. In the meantime, there has got to be a simple solution to fix this.