使用hibernate自动创建Mysql表失败原因
2018-03-16 23:03
405 查看
1.使用 schemaExport(hibernate5.2.3)创建Mysql表@Test
public void testSchemaExport() {
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().configure().build();
Metadata metadata = new MetadataSources(serviceRegistry).buildMetadata();
SchemaExport schemaExport = new SchemaExport();
schemaExport.create(EnumSet.of(TargetType.DATABASE), metadata);
}
2.使用上面的代码可以生成SQL但是建表别没有成功;Hibernate:
create table User (
id integer not null,
age integer,
name ),
primary key (id)
) type=InnoDB
把hibernate生成的SQL语句在Navicat中执行出现错误;[Err] 1064 - 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 'Hibernate:
create table User (
id integer not null,
age ' at line 1
3.经过查找发现是hibernate里的dialect和Mysql的版本不匹配,SQL语句里的type=InnoDB使用在MySQL5.0之前,5.0之后就要是使用engine=InnoDBMySql5.0之前的配置
<property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
5.0之后需要使用
<property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
4.修改后的hibernate生成SQL语句如下,建表成功;Hibernate:
create table User (
id integer not null,
age integer,
name ),
primary key (id)
) ENGINE=InnoDB
public void testSchemaExport() {
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().configure().build();
Metadata metadata = new MetadataSources(serviceRegistry).buildMetadata();
SchemaExport schemaExport = new SchemaExport();
schemaExport.create(EnumSet.of(TargetType.DATABASE), metadata);
}
2.使用上面的代码可以生成SQL但是建表别没有成功;Hibernate:
create table User (
id integer not null,
age integer,
name ),
primary key (id)
) type=InnoDB
把hibernate生成的SQL语句在Navicat中执行出现错误;[Err] 1064 - 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 'Hibernate:
create table User (
id integer not null,
age ' at line 1
3.经过查找发现是hibernate里的dialect和Mysql的版本不匹配,SQL语句里的type=InnoDB使用在MySQL5.0之前,5.0之后就要是使用engine=InnoDBMySql5.0之前的配置
<property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
5.0之后需要使用
<property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
4.修改后的hibernate生成SQL语句如下,建表成功;Hibernate:
create table User (
id integer not null,
age integer,
name ),
primary key (id)
) ENGINE=InnoDB
相关文章推荐
- 使用hibernate自动创建Mysql表失败原因
- 用hibernate自动创建mysql表,添加失败org.hibernate.exception.SQLGrammarException
- 用hibernate自动创建mysql表,添加失败org.hibernate.exception.SQLGrammarException
- fopen自动创建文件失败的原因
- 使用Hibernate自动生成表不能正确创建表的问题
- (一)小记——驱动中使用class_device_create()报错的原因、自动创建设备节点
- 使用Hibernate自动生成表不能正确创建表的问题
- 使用hibernate根据配置的实体bean类无法自动创建数据库表
- 使用springDataJpa自动创建了我不知道的hibernate_sequence表,在回事? 撸它就是这么easy....
- 使用SSH Hibernate自动创建表的问题:Could not parse mapping document from input stream
- 驱动中使用class_device_create()报错的原因,自动创建设备节点
- Hibernate自动建表失败原因总结
- hibernate使用注解自动创建自增主键
- JPA项目使用myeclipse创建带注解的model实体类&web工程使用MyEclipse自动生成hibernate映射文件和实体类
- 使用Spring集成Hibernate配置,根据实体类自动创建表
- Xcode 9 在 Jenkins 自动打包脚本 中使用 Xcode integration 插件打包失败的原因
- hibernate无法自动创建表的原因整理
- 自动创建hibernate的hbm.xml文件失败
- hibernate4.x自动建表时候创建外键失败ERROR: HHH000389: Unsuccessful: alter table ORDERS_NOPK1 add index
- 使用hibernate自动创建数据库表格为啥产生两个中间表