Hello, we have some projects created with Hibernate 4. At moving them to Hibernate 5.2.1 we run into a problem with Mysql databases:
When the @Table name of an Entity is set to a quoted String like in the following example, the table can be created with hibernate. But when"javax.persistence.schema-generation.database.action" or "hibernate.hbm2ddl.auto" is set to "validate", it doesn't know the table any more.
Entity: {code:java} @Entity @Table(name = "`Language`") public class Language { private int id; private String description;
@Id @GeneratedValue(strategy = GenerationType.AUTO) public int getId() { return id; } ... } {code}
In the example project, the database table for this entity is created at first application start with hibernate's schema generation without problems: {noformat} <property name="javax.persistence.schema-generation.database.action" value="create-drop" /> {noformat}
After switching this property to {noformat} <property name="javax.persistence.schema-generation.database.action" value="validate" /> {noformat} now building the EntityManagerFactory/Sessionfactory fails, because schema validation doesn't find this table any more.
{code:java} Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit: hibernate5example] Unable to build Hibernate SessionFactory at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:961) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:891) at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:58) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39) at com.company.example.App.main(App.java:18) Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing table [`Language`] at org.hibernate.tool.schema.internal.SchemaValidatorImpl.validateTable(SchemaValidatorImpl.java:130) at org.hibernate.tool.schema.internal.SchemaValidatorImpl.performValidation(SchemaValidatorImpl.java:100) at org.hibernate.tool.schema.internal.SchemaValidatorImpl.doValidation(SchemaValidatorImpl.java:67) ... {code}
With Hibernate 4.3, validation works for such entities.
The [MySQL databases' "lower_case_table_names" value|http://dev.mysql.com/doc/refman/5.5/en/identifier-case-sensitivity.html] is set to "1" |
|