Hibernate不会自动创建表
我有Hibernate和Spring框架的Maven项目。 我希望Hibernate自动创建表,但是只删除所有现有表并且不创建所需的表。 在会话工厂初始化期间不会抛出exception,但是当我尝试保存Player
实体时,抛出exception:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:表’billboarddb.player’不存在
如果我手动创建表并将属性hibernate.hbm2ddl.auto
更改为"validate"
,那么一切正常。 你有什么想法,为什么Hibernate不创建表?
Spring配置文件:
/WEB-INF/config/jdbc.properties ${hibernate.dialect} ${hibernate.show_sql} ${hibernate.hbm2ddl.auto} ${hibernate.c3p0.min_size} ${hibernate.c3p0.max_size} ${hibernate.c3p0.timeout} ${hibernate.c3p0.max_statements}
jdbc.properties文件:
hibernate.connection.driver_class=com.mysql.jdbc.Driver hibernate.connection.url=jdbc:mysql://127.0.0.1:3306/BillboardDB hibernate.connection.username=root hibernate.connection.password=1234 hibernate.default_schema=BillboardDB hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect hibernate.hbm2ddl.auto=create hibernate.show_sql=true hibernate.c3p0.min_size=5 hibernate.c3p0.max_size=20 hibernate.c3p0.timeout=1800 hibernate.c3p0.max_statements=50
Hibernate依赖项:
org.hibernate hibernate-entitymanager ${hibernateVersion} org.hibernate hibernate-c3p0 ${hibernateVersion} org.hibernate hibernate-tools ${hibernateToolsVersion}
我解决了这个问题。 Hibernate无法使用MysqlInnoDBDialect创建表。 现在我改用MySQL5InnoDBDialect。
将以下条目添加到hibernateProperties props。
create