hbm2ddl.auto设置为update时不能工作排查方法!
来源:互联网 发布:手机视频剪辑软件中文 编辑:程序博客网 时间:2024/06/16 10:21
问题描述:
在调试hibernate的时候发现设置hbm2ddl.auto设置为update是不能工作,eclipse中报如下错误:
Hibernate: insert into news (title, content) values (?, ?)
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not insert: [com.ericsson.ewanbao.News]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
...................
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'hibernate.news' doesn't exist
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
...............
问题分析:
经检查数据库发现,news表确实创建不成功,可见hbm2ddl.auto设置为update没有能够建立表
解决步骤:
1.把mysql的general-log打开,这样可以跟踪所有的sql语句;
2.再次执行程序,在general-log的最后发现如下sql语句:
3 Query SHOW FULL TABLES FROM `hibernate` LIKE 'news'
3 Query create table news (id integer not null auto_increment, title varchar(255), content varchar(255), primary key (id)) type=InnoDB
3 Query SHOW FULL TABLES FROM `hibernate` LIKE 'PROBABLYNOT'
3 Query SET autocommit=0
3 Query SET autocommit=1
3 Query SET autocommit=0
3 Query insert into news (title, content) values ('???????', '???????????!')
3 Query SHOW FULL TABLES FROM `hibernate` LIKE 'PROBABLYNOT'
3.可以发现hibernate已经发送了见表语句给数据库,为什么建表没有成功了?尝试拷贝这些建表语句到sql控制台执行,得到如下结果:
mysql> create table news (id integer not null auto_increment, title varchar(255), content varchar(255), primary key (id)
) type=InnoDB;
ERROR 1064 (42000): 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 1
4.可以看到是sql语句错误,经分析发现是hibernate.dialect的设置错误,原先设置为org.hibernate.dialect.MySQLInnoDBDialect,应该修改为org.hibernate.dialect.MySQL5InnoDBDialect
在调试hibernate的时候发现设置hbm2ddl.auto设置为update是不能工作,eclipse中报如下错误:
Hibernate: insert into news (title, content) values (?, ?)
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not insert: [com.ericsson.ewanbao.News]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
...................
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'hibernate.news' doesn't exist
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
...............
问题分析:
经检查数据库发现,news表确实创建不成功,可见hbm2ddl.auto设置为update没有能够建立表
解决步骤:
1.把mysql的general-log打开,这样可以跟踪所有的sql语句;
2.再次执行程序,在general-log的最后发现如下sql语句:
3 Query SHOW FULL TABLES FROM `hibernate` LIKE 'news'
3 Query create table news (id integer not null auto_increment, title varchar(255), content varchar(255), primary key (id)) type=InnoDB
3 Query SHOW FULL TABLES FROM `hibernate` LIKE 'PROBABLYNOT'
3 Query SET autocommit=0
3 Query SET autocommit=1
3 Query SET autocommit=0
3 Query insert into news (title, content) values ('???????', '???????????!')
3 Query SHOW FULL TABLES FROM `hibernate` LIKE 'PROBABLYNOT'
3.可以发现hibernate已经发送了见表语句给数据库,为什么建表没有成功了?尝试拷贝这些建表语句到sql控制台执行,得到如下结果:
mysql> create table news (id integer not null auto_increment, title varchar(255), content varchar(255), primary key (id)
) type=InnoDB;
ERROR 1064 (42000): 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 1
4.可以看到是sql语句错误,经分析发现是hibernate.dialect的设置错误,原先设置为org.hibernate.dialect.MySQLInnoDBDialect,应该修改为org.hibernate.dialect.MySQL5InnoDBDialect
- hbm2ddl.auto设置为update时不能工作排查方法!
- hbm2ddl.auto设置为update时不能工作排查方法!
- hibernate.hbm2ddl.auto设置为update时数据库没有自动生成表结构
- hibernate.hbm2ddl.auto为update无法自动建表
- hibernate.hbm2ddl.auto设置成update的问题
- hbm2ddl.auto 的设置
- hibernate.hbm2ddl.auto=update
- hibernate.hbm2ddl.auto设置为updata时需要注意的地方
- hibernate.hbm2ddl.auto的update属性不能创建表的问题
- hibernate.hbm2ddl.auto 的设置
- hibernate.hbm2ddl.auto 的设置
- hibernate.hbm2ddl.auto 的设置
- hibernate.hbm2ddl.auto 的设置
- hibernate.hbm2ddl.auto 的设置
- hibernate.hbm2ddl.auto 的设置
- hibernate 设置hbm2ddl.auto=create不能自动建表问题
- 关于hibernate.hbm2ddl.auto 的设置
- 关于hibernate.hbm2ddl.auto 的设置
- 用Activex控件(cab)自动部署软件:Activex开发和发布过程与总结。
- js的内置对象
- opencv检测人脸
- 优秀CIO应注重企业机构整合
- Linux makefile 教程 非常详细,且易懂 .
- hbm2ddl.auto设置为update时不能工作排查方法!
- STL以及内存以及类的默认函数-题目
- js事件
- 浅谈 java 设计模式--工厂方法模式(Factory Method pattern)
- 实现Vim tags自动更新
- ALSA的配置文件
- 2012 BI发展趋势预测
- 在数组中存储对象
- MYSQL常用命令