解决Hibernate4连接MySQL5.5数据库无法自动创建表的问题
2015-12-01 17:31
543 查看
hibernate4连接mysql自动创建表的时候出现了错误
好长时间不用Hibernate了,最近又重新温习了一下,写了一个hello world 级别的代码,但是怎么都无法创建表,以前也没有碰到这种问题啊,控制台的错误如下:
在网上搜了一下发现,原来是type=InnoDB 是MySQL5.0之前版本使用的,我的数据库是MySQL5.5的,所以需要把hibernate.cfg.xml配置文件中的dialect改一下,
原来的:<property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
改后:<property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
好长时间不用Hibernate了,最近又重新温习了一下,写了一个hello world 级别的代码,但是怎么都无法创建表,以前也没有碰到这种问题啊,控制台的错误如下:
十二月 01, 2015 5:25:01 下午 org.hibernate.annotations.common.Version <clinit> INFO: HCANN000001: Hibernate Commons Annotations {4.0.2.Final} 十二月 01, 2015 5:25:01 下午 org.hibernate.Version logVersion INFO: HHH000412: Hibernate Core {4.2.4.Final} 十二月 01, 2015 5:25:01 下午 org.hibernate.cfg.Environment <clinit> INFO: HHH000206: hibernate.properties not found 十二月 01, 2015 5:25:01 下午 org.hibernate.cfg.Environment buildBytecodeProvider INFO: HHH000021: Bytecode provider name : javassist 十二月 01, 2015 5:25:01 下午 org.hibernate.cfg.Configuration configure INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml 十二月 01, 2015 5:25:01 下午 org.hibernate.cfg.Configuration getConfigurationInputStream INFO: HHH000040: Configuration resource: /hibernate.cfg.xml 十二月 01, 2015 5:25:01 下午 org.hibernate.cfg.Configuration addResource INFO: HHH000221: Reading mappings from resource: com/lym/hibernate/entity/News.hbm.xml 十二月 01, 2015 5:25:01 下午 org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide! 十二月 01, 2015 5:25:01 下午 org.hibernate.cfg.Configuration doConfigure INFO: HHH000041: Configured SessionFactory: null 十二月 01, 2015 5:25:01 下午 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!) 十二月 01, 2015 5:25:01 下午 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000115: Hibernate connection pool size: 20 十二月 01, 2015 5:25:01 下午 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000006: Autocommit mode: false 十二月 01, 2015 5:25:01 下午 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://127.0.0.1:3306/hibernate5] 十二月 01, 2015 5:25:01 下午 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000046: Connection properties: {user=root, password=****} 十二月 01, 2015 5:25:02 下午 org.hibernate.dialect.Dialect <init> INFO: HHH000400: Using dialect: <span style="color:#CC0000;">org.hibernate.dialect.MySQLInnoDBDialect</span> 十二月 01, 2015 5:25:02 下午 org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService INFO: HHH000399: Using default transaction strategy (direct JDBC transactions) 十二月 01, 2015 5:25:02 下午 org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init> INFO: HHH000397: Using ASTQueryTranslatorFactory 十二月 01, 2015 5:25:02 下午 org.hibernate.tool.hbm2ddl.SchemaExport execute INFO: HHH000227: Running hbm2ddl schema export Hibernate: drop table if exists NEWS Hibernate: create table NEWS ( ID integer not null auto_increment, TITLE varchar(255), AUTHOR varchar(255), DATE date, primary key (ID) ) type=InnoDB 十二月 01, 2015 5:25:02 下午 org.hibernate.tool.hbm2ddl.SchemaExport perform ERROR: HHH000389: Unsuccessful: create table NEWS (ID integer not null auto_increment, TITLE varchar(255), AUTHOR varchar(255), DATE date, primary key (ID)) <span style="color:#CC0000;">type=InnoDB</span> 十二月 01, 2015 5:25:02 下午 org.hibernate.tool.hbm2ddl.SchemaExport perform ERROR: 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 '<span style="color:#CC0000;">type=InnoDB</span>' at line 7 十二月 01, 2015 5:25:02 下午 org.hibernate.tool.hbm2ddl.SchemaExport execute INFO: HHH000230: Schema export complete Hibernate: insert into NEWS (TITLE, AUTHOR, DATE) values (?, ?, ?) 十二月 01, 2015 5:25:02 下午 org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions WARN: SQL Error: 1146, SQLState: 42S02 十二月 01, 2015 5:25:02 下午 org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions ERROR: Table 'hibernate5.news' doesn't exist
在网上搜了一下发现,原来是type=InnoDB 是MySQL5.0之前版本使用的,我的数据库是MySQL5.5的,所以需要把hibernate.cfg.xml配置文件中的dialect改一下,
原来的:<property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
改后:<property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
相关文章推荐
- 查看MySQL配置文件路径及相关配置
- 查看MySQL配置文件路径及相关配置
- MySQLCluster7.2.15安装部署性能测试
- Mysql命令行添加用户
- Mysql命令行添加用户
- 查看mysql表结构和表创建语句的方法
- MySQL碎碎念
- update inner join 使用
- 采用Atlas+Keepalived实现MySQL读写分离、读负载均衡
- mysql中间件研究(Atlas,cobar,TDDL)
- MySQL中导出用户权限设置的脚本
- MySQL中导出用户权限设置的脚本
- MySQL数据库的初始化mysql_install_db
- [转] Mysql 数据库引擎
- MySQL复制表结构,表数据。
- 通过MySQL慢查询日志定位执行效率低的SQL语句
- mysql主从复制
- mysql 建表字符集【转】
- [转]MySQLHelper类
- [转]C#连接操作mysql实例