使用hibernate自动创建Mysql表失败原因
2016-11-22 08:39
253 查看
1.使用 schemaExport(hibernate5.2.3)创建Mysql表
2.使用上面的代码可以生成SQL但是建表别没有成功;
把hibernate生成的SQL语句在Navicat中执行出现错误;
3.经过查找发现是hibernate里的dialect和Mysql的版本不匹配,SQL语句里的type=InnoDB使用在MySQL5.0之前,5.0之后就要是使用engine=InnoDB
4.修改后的hibernate生成SQL语句如下,建表成功;
@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 varchar(255), 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=InnoDB
MySql5.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 varchar(255), primary key (id) ) ENGINE=InnoDB
相关文章推荐
- 使用hibernate自动创建Mysql表失败原因
- 用hibernate自动创建mysql表,添加失败org.hibernate.exception.SQLGrammarException
- 用hibernate自动创建mysql表,添加失败org.hibernate.exception.SQLGrammarException
- 使用hibernate自动在MYSQL中创建表,极其简单,改下配置文件。
- Hibernate之——使用SchemaExport类自动创建数据库表
- hibernate4.x自动建表时候创建外键失败ERROR: HHH000389: Unsuccessful: alter table ORDERS_NOPK1 add index
- 使用SSH Hibernate自动创建表的问题:Could not parse mapping document from input stream
- 使用springDataJpa自动创建了我不知道的hibernate_sequence表,在回事? 撸它就是这么easy....
- 使用Hibernate自动生成表不能正确创建表的问题
- 使用Spring集成Hibernate配置,根据实体类自动创建表
- (一)小记——驱动中使用class_device_create()报错的原因、自动创建设备节点
- hibernate 配置自动生成表 失败的原因
- castle 1.0 RC1 中使用“自动事务”facility后,并发较大的情况下,造成创建proxy失败
- hibernate无法自动创建表的原因整理
- fopen自动创建文件失败的原因
- 自动创建hibernate的hbm.xml文件失败
- Xcode 9 在 Jenkins 自动打包脚本 中使用 Xcode integration 插件打包失败的原因
- JPA项目使用myeclipse创建带注解的model实体类&web工程使用MyEclipse自动生成hibernate映射文件和实体类
- 使用hibernate自动创建数据库表格为啥产生两个中间表
- 使用hibernate根据配置的实体bean类无法自动创建数据库表