您的位置:首页 > 数据库 > MySQL

解决Hibernate4连接MySQL5.5数据库无法自动创建表的问题

2015-12-01 17:31 543 查看
hibernate4连接mysql自动创建表的时候出现了错误

好长时间不用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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: