hbm2ddl.auto设置为update时不能工作排查方法!
2015-07-10 09:40
344 查看
问题描述:
在调试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
相关文章推荐
- Build error handing
- 单例设计模式
- selector和shape结合设置控件样式
- BitTorrent协议规范
- 关于facebook infer 静态代码审查工具
- List GetEnumerator
- jQuery禁用鼠标右键
- 外部链接
- nyoj115 城市平乱(dijkstra算法)
- codeforce 3D. Least Cost Bracket Sequence(贪心)
- 今天是个好日子o
- “黑马程序员“Java中的强制类型转换是如何转换的?
- JAVA入门基础笔记--string类型
- LeetCode || Add Two Numbers
- Xamarin For Android 打包编译APK文件详细图文教程
- Jni中C++和Java的参数传递
- NSMutableString与NSString一些用法
- JAVA入门基础笔记-数组类型
- java(Web)中相对路径,绝对路径问题总结
- 简述Jquery与DOM对象