java TYPE 上的 MySQL 5.5.9 和 Hibernate 表创建错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5231325/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MySQL 5.5.9 and Hibernate table creation error on TYPE
提问by Nico Huysamen
While trying to recreate my database using Hibernate + Spring, the SQL that get's generated appends "type=InnoDB"
to the end of each creation statement. This seems to cause problems with my MySQL5.5.9 setup. It produces the following error:
在尝试使用 Hibernate + Spring 重新创建我的数据库时,生成的 SQL 附加"type=InnoDB"
到每个创建语句的末尾。这似乎会导致我的 MySQL5.5.9 设置出现问题。它产生以下错误:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'type=InnoDB' at line 1
你的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 1 行的“type=InnoDB”附近使用的正确语法
If I manually remove the type=InnoBD and paste the create command in MySQL, it works fine.
如果我手动删除 type=InnoBD 并在 MySQL 中粘贴 create 命令,它工作正常。
Has someone else come across this error? Is it maybe just a MySQL setting that I need to change? I am using the my-innodb-heavy-4G.cnf
template as my /etc/my.cnf
.
有其他人遇到过这个错误吗?它可能只是我需要更改的 MySQL 设置吗?我使用my-innodb-heavy-4G.cnf
模板作为我的/etc/my.cnf
.
I also know that the type
syntax has been deprecated by MySQL, and that engine
should be used (and it does if I manually alter the create statements). Is there any way to configure this in Hibernate?
我也知道type
MySQL 不推荐使用该语法,engine
应该使用它(如果我手动更改 create 语句,它会这样做)。有没有办法在 Hibernate 中配置它?
Thanks
谢谢
回答by axtavt
Use MySQL5InnoDBDialect
instead of MySQLInnoDBDialect
.
使用MySQL5InnoDBDialect
代替MySQLInnoDBDialect
。
回答by redBeard
Using 'MySQL5InnoDBDialect' works with 5.1 and 5.5.
使用“MySQL5InnoDBDialect”适用于 5.1 和 5.5。
回答by Sergey Shcherbakov
Just in case if you have changed to org.hibernate.dialect.MySQL5InnoDBDialect (e.g. on MariaDB) and still getting the error check whether the table name (or any other in the query) is not a reserved word or existing object name (e.g. 'position').
以防万一,如果您已更改为 org.hibernate.dialect.MySQL5InnoDBDialect(例如在 MariaDB 上)并且仍然收到错误,请检查表名(或查询中的任何其他名称)是否不是保留字或现有对象名称(例如 '位置')。
回答by Saeed Afzal
In Grails:
在 Grails 中:
Change the dialect statement in DataSource.groovy
更改 DataSource.groovy 中的方言语句
Example:
例子:
Use "dialect=org.hibernate.dialect.MySQL5InnoDBDialect" instead of "dialect=org.hibernate.dialect.MySQLInnoDBDialect"
使用“dialect=org.hibernate.dialect.MySQL5InnoDBDialect”而不是“dialect=org.hibernate.dialect.MySQLInnoDBDialect”
You can use the same approach for your project i guess.
我猜您可以对您的项目使用相同的方法。
Thanks
谢谢
回答by Pramod
After adding MySQL5InnoDBDialect, I got same error but with "Engine=InnoDB". So I added MySQL5InnoDBDialect in properties file and removed @Table annotations from model file.
添加 MySQL5InnoDBDialect 后,我遇到了同样的错误,但出现了“Engine = InnoDB”。所以我在属性文件中添加了 MySQL5InnoDBDialect 并从模型文件中删除了 @Table 注释。
回答by Rael Gugelmin Cunha
type
is deprecated, and removed from newest versions. Use engine=InnoDB
type
已弃用,并从最新版本中删除。利用engine=InnoDB
回答by edwindh
No meu caso, instalei o MySQL v5.6.20, e ao rodar minha aplica??o que usa Hibernate, teve colocar MySQL5InnoDBDialect.
没有 meu caso, instalei o MySQL v5.6.20, e ao rodar minha aplica??o que usa Hibernate, teve colocar MySQL5InnoDBDialect。
Segue o trecho (persistence.xml) da tag properties:
Segue o trecho (persistence.xml) da 标签属性:
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/livrariadb" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="****" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
</properties>