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

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>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值