mysql数据库方言的选择问题

1.问题引导

    在开发项目的时候,我接受到一个用spring+hibernate+springMVC的项目demo,hibernate用的jpa规范,我配置hibernate.hbm2ddl.auto=create,这样程序本应该一运行就创建表,然而当我,向数据库中添加数据的时候就报错:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'test.userinfo' doesn't exist

说我操作的表不存在。然后,我设置hibernate.show_sql=true,查看日志发现有创建数据库表的语句


Hibernate: 
    drop table if exists userinfo
Hibernate: 
    create table userinfo (
        id integer not null auto_increment unique,
        address varchar(255),
        age integer,
        birthday datetime,
        name varchar(255),
        password varchar(255),
        primary key (id)
    ) type=InnoDB
2017-07-05 21:31:59,052 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] - <HHH000389: Unsuccessful: create table userinfo (id integer not null auto_increment unique, address varchar(255), age integer, birthday datetime, name varchar(255), password varchar(255), primary key (id)) type=InnoDB>
2017-07-05 21:31:59,053 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] - <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 'type=InnoDB' at line 9>
七月 05, 2017 9:31:59 下午 org.apache.catalina.core.ApplicationContext log

仔细查看日志发现,说我们创建数据库的语句有问题

然后,我把数库方言改为  hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect

2.mysql不同版本对应的方言


MySQL 5.5及以上版本  :  org.hibernate.dialect.MySQL5InnoDBDialect  这个是网上人说的,我安装的就是mysql 5.5,开始方言用的org.hibernate.dialect.MySQLInnoDBDialect老报错,改了之后就正常了,实践证明这是正确的。


MySQL 5.5以下的

org.hibernate.dialect.MySQLInnoDBDialect,这个是推测吧,我没有试过


org.hibernate.dialect.MySQLDialect 这个方言好像通用的



  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

q1054261752

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值