generator中使用increment经验总结(hibernate)
来源:互联网 发布:我国进口商品市场数据 编辑:程序博客网 时间:2024/05/16 11:28
generator中使用increment经验总结(hibernate)
tomcat5.5+struts+hibernate2.1+jtds_jdbc+sqlserver2000项目
在hibernate中我本来想在generator中使用native自动让系统选择generator类型,select,update,del正确,但insert时候报错:
[ERROR] TableGenerator - could not read a hi value <java.sql.SQLException: 第 1 行: FOR UPDATE 子句仅允许用于 DECLARE CURSOR。>java.sql.SQLException: 第 1 行: FOR UPDATE 子句仅允许用于 DECLARE CURSOR。
at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:365)
at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2781)
..............
[DEBUG] JDBCExceptionReporter - SQL Warning <java.sql.SQLWarning: Preparing the statement failed: 第 1 行: FOR UPDATE 子句仅允许用于 DECLARE CURSOR。>java.sql.SQLWarning: Preparing the statement failed: 第 1 行: FOR UPDATE 子句仅允许用于 DECLARE CURSOR。
................
Caused by: java.sql.SQLException: 第 1 行: FOR UPDATE 子句仅允许用于 DECLARE CURSOR。
...............
[WARN] JDBCExceptionReporter - SQL Warning: 1003, SQLState: S1000
[WARN] JDBCExceptionReporter - Preparing the statement failed: 第 1 行: FOR UPDATE 子句仅允许用于 DECLARE CURSOR。
[ERROR] JDBCExceptionReporter - Could not save object <java.sql.SQLException: 第 1 行: FOR UPDATE 子句仅允许用于 DECLARE CURSOR。>java.sql.SQLException: 第 1 行: FOR UPDATE 子句仅允许用于 DECLARE CURSOR。
................
然后我选择用identity,在sqlserver中选择标识递增,希望sqlserver自己帮我递增id号.但是报错:
[ERROR] ReflectHelper - IllegalArgumentException in class: com.shjinbang.hibernate.User, setter method of property: userid
[ERROR] ReflectHelper - expected type: java.lang.Integer, actual value: java.lang.Long
[WARN] UserDAO - net.sf.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling: argument type mismatch setter of com.shjinbang.hibernate.User.userid
[DEBUG] JDBCTransaction - rollback
我又选择increment,让hibernate帮我递增id号,也是以上的错误.
我修改了与数据库映射的Java类,将Integer改成Long类型,同时在对应的hibernate映射文件 ,User.hbm.xml文件中将
<id column="userid" name="userid" type="long"> 这里的type类型从 Integer 改成 long类型.
运行成功.
我估计increment和identity都是可以正确使用的,就是很奇怪的是:必须用Long类型才能递增id号?
- generator中使用increment经验总结(hibernate)
- hibernate 抛出could not fetch initial value for increment generator
- hibernate中identity和increment区别
- hibernate中identity和increment区别
- hibernate中identity和increment区别
- hibernate中identity和increment区别
- hibernate中identity和increment区别
- hibernate中identity和increment区别
- hibernate中identity和increment区别
- hibernate 的小问题 could not fetch initial value for increment generator
- org.hibernate.exception.SQLGrammarException: could not fetch initial value for increment generator
- Hibernate的中使用<generator>设置主键的生成方式
- Hibernate使用中关于generator标签中的值的选择
- s2sh中hibernate中identity和increment区别
- hibernate中native、identity和increment等主键的区别
- hibernate中native、identity和increment等主键的区别
- hibernate中native、identity和increment等主键的区别
- hibernate中native、identity和increment等主键的区别
- SQL注入天书—ASP注入漏洞全接触
- 用java实现高性能与高扩展性的文件传输系统====》综述
- 五月,我们骑车去香格里拉
- 求最大公约数的函数
- 使用BeanUtils.copyProperties()产生的错误
- generator中使用increment经验总结(hibernate)
- hibernate编程经验
- 中文字符转化
- 呵呵,今天原来是愚人节,可惜放假,无人可愚。
- Peercast简介
- sqlserver中用了user关键子出现的问题
- MD5
- Linux下最常用的基本操作命令
- Fedora Core 5.0 中添加字体及应用程序字体设置方法