Invalid syntax error quot;type= MyISAMquot; in DDL generated by Hibernate(无效的语法错误“type=MyISAM在 Hibernate 生成的 DDL 中)
问题描述
我的 Java 代码出现此错误
I am getting this error for my Java code
Caused by :`com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException`: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB` server version for the right syntax to use near 'type = `MyISAM`' at line 1
这是hibernate传递的查询:
This is the query passed by hibernate:
Hibernate: create table EMPLOYEE (emp_id integer not null, FNAME varchar(255), LNAME varchar(255), primary key (emp_id)) type=MyISAM
我查看了与此错误相关的所有问题.但在所有这些问题中,用户本身都在传递查询type = MyISAM
",因此他们可以将type
"更改为engine
",但是这里hibernate负责创建表,所以我不明白错误在哪里,以及如何修复它.
I have looked at all questions related to this error. But in all that questions the user itself is passing query "type = MyISAM
" so they can change "type
" to "engine
", but here hibernate is responsible for creating table, so I don't understand where the mistake is, and how I can fix it.
这是我的配置文件:
<hibernate-configuration>
<session-factory >
<property name="hibernate.hbm2ddl.auto">create</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/servletcheck</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"> </property>
<property name="hibernate.dialect"> org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.show_sql">true</property>
<mapping resource="Employee.hbm.xml"/>
</session-factory>
</hibernate-configuration>
这是我的映射文件:
<hibernate-mapping>
<class name="first.Employee" table="EMPLOYEE">
<id name="id" type="int">
<column name="emp_id" />
<generator class="assigned" />
</id>
<property name="fname" type="java.lang.String">
<column name="FNAME" />
</property>
<property name="lname" type="java.lang.String">
<column name="LNAME" />
</property>
</class>
</hibernate-mapping>
这是我的类文件:
public class StoreData {
public static void main(String[] args) {
Configuration cfg=new Configuration();
cfg.configure("hibernate.cfg.xml");
SessionFactory factory=cfg.buildSessionFactory();
Session session=factory.openSession();
org.hibernate.Transaction t=session.beginTransaction();
Employee e=new Employee();
e.setId(1);
e.setFname("yogesh");
e.setLname("Meghnani");
session.persist(e);
t.commit();
}
}
推荐答案
问题在于 - 在 Hibernate 5.x 及更早版本中 - 方言 org.hibernate.dialect.MySQLDialect
适用于 MySQL 4.x 或更早版本.此方言生成的片段 TYPE=MYISAM
在 MySQL 4.0 中已弃用,并在 5.5 中删除.
The problem is that - in Hibernate 5.x and earlier - the dialect org.hibernate.dialect.MySQLDialect
is for MySQL 4.x or earlier. The fragment TYPE=MYISAM
that is generated by this dialect was deprecated in MySQL 4.0 and removed in 5.5.
鉴于您使用 MariaDB,您需要使用(取决于 MariaDB 的版本和 - 也许 - Hibernate 的版本)以下之一:
Given that you use MariaDB, you need to use (depending on the version of MariaDB and - maybe - the version of Hibernate) one of:
org.hibernate.dialect.MariaDBDialect
org.hibernate.dialect.MariaDB53Dialect
如果您使用的是 MySQL,或者如果您的 Hibernate 版本中不存在上述 MariaDB 的两种方言:
If you are using MySQL, or if the above two dialects for MariaDB don't exist in your version of Hibernate:
org.hibernate.dialect.MySQL5Dialect
org.hibernate.dialect.MySQL55Dialect
org.hibernate.dialect.MySQL57Dialect
这篇关于无效的语法错误“type=MyISAM"在 Hibernate 生成的 DDL 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无效的语法错误“type=MyISAM"在 Hibernate 生成的 DDL 中
基础教程推荐
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 降序排序:Java Map 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01