错误提示:
2010-10-11 17:37:18 org.apache.struts.action.RequestProcessor Unhandled Exception thrown: class org.springframework.orm.hibernate3.HibernateSystemException
javax.servlet.ServletException: org.springframework.orm.hibernate3.HibernateSystemException: identifier of an instance of com.chgreatwall.ycjl.gl.webservice.domain.Cigarette was altered from 7304 to 7760; nested exception is org.hibernate.HibernateException: identifier of an instance of com.chgreatwall.ycjl.gl.webservice.domain.Cigarette was altered from 7304 to 7760
背景:
读取excel文件,导入数据库
源代码:
public void iniCigarette() {
Cigarette cigarette = new Cigarette();
String filename = "Cigarette"; // Excel文件名
try {
Workbook book = Workbook.getWorkbook(new File("H:\\"
+ filename + ".xls"));
Sheet se = book.getSheet(0);//得到第1个sheet(Excel通常会有3个Sheet)
int rownum = se.getRows(); //得到总行数
for(int i=1;i<rownum;i++){
System.out.println(i);
cigarette.setPkId(Integer.parseInt(se.getCell(0, i).getContents()));
cigarette.setItemCode(se.getCell(1, i).getContents());
cigarette.setItemId(se.getCell(2, i).getContents());
cigarette.setItemName(se.getCell(3, i).getContents());
cigarette.setShortName(se.getCell(4, i).getContents());
cigarette.setUmid(se.getCell(5, i).getContents());
cigarette.setPackBar(se.getCell(6, i).getContents());
cigarette.setBoxBar(se.getCell(7, i).getContents());
cigarette.setBigBoxBar(se.getCell(8, i).getContents());
cigarette.setStandBarName(se.getCell(9, i).getContents());
cigarette.setUmsale(se.getCell(10, i).getContents());
cigarette.setUmsaleName(se.getCell(11, i).getContents());
cigarette.setSaleUmsize(se.getCell(12, i).getContents());
cigarette.setTaxId(se.getCell(13, i).getContents());
cigarette.setTaxValue(se.getCell(14, i).getContents());
cigarette.setCantId(se.getCell(15, i).getContents());
cigarette.setCantName(se.getCell(16, i).getContents());
cigarette.setShelfPer(se.getCell(17, i).getContents());
cigarette.setColour(se.getCell(18, i).getContents());
cigarette.setItemKind(se.getCell(19, i).getContents());
cigarette.setItemIdcct(se.getCell(20, i).getContents());
cigarette.setStandBarCode(se.getCell(21, i).getContents());
cigarette.setIsNormal(se.getCell(22, i).getContents());
cigarette.setSpec(se.getCell(23, i).getContents());
cigarette.setKind(se.getCell(24, i).getContents());
cigarette.setTarCount(se.getCell(25, i).getContents());
cigarette.setGasNicotine(se.getCell(26, i).getContents());
cigarette.setCocont(se.getCell(27, i).getContents());
cigarette.setBarKind(se.getCell(28, i).getContents());
cigarette.setBarKey(se.getCell(29, i).getContents());
cigarette.setPackKind(se.getCell(30, i).getContents());
cigarette.setProductType(se.getCell(31, i).getContents());
cigarette.setFnational(se.getCell(32, i).getContents());
cigarette.setIsImported(se.getCell(33, i).getContents());
cigarette.setBarType(se.getCell(34, i).getContents());
cigarette.setFilterColor(se.getCell(35, i).getContents());
cigarette.setDescription(se.getCell(36, i).getContents());
cigarette.setUnitCost(se.getCell(37, i).getContents());
cigarette.setShortCode(se.getCell(38, i).getContents());
cigarette.setBrdType(se.getCell(39, i).getContents());
cigarette.setItemKind1(se.getCell(40, i).getContents());
cigarette.setAbc(se.getCell(41, i).getContents());
cigarette.setItemType1(se.getCell(42, i).getContents());
cigarette.setItemType1name(se.getCell(43, i).getContents());
cigarette.setItemType2(se.getCell(44, i).getContents());
cigarette.setItemType2name(se.getCell(45, i).getContents());
cigarette.setCategory(se.getCell(46, i).getContents());
cigarette.setBrandId(se.getCell(47, i).getContents());
cigarette.setBrandName(se.getCell(48, i).getContents());
cigarette.setMfrid(se.getCell(49, i).getContents());
cigarette.setMfrname(se.getCell(50, i).getContents());
cigarette.setNetDate(se.getCell(51, i).getContents());
cigarette.setIsMrb(se.getCell(52, i).getContents());
cigarette.setIsHundredBrand(se.getCell(53, i).getContents());
cigarette.setIsLowend(se.getCell(54, i).getContents());
cigarette.setIsRare(se.getCell(55, i).getContents());
cigarette.setIsMature(se.getCell(56, i).getContents());
cigarette.setUpLimitRate(se.getCell(57, i).getContents());
cigarette.setDownLimitRate(se.getCell(58, i).getContents());
cigarette.setDealType(se.getCell(59, i).getContents());
cigarette.setIsCosting(se.getCell(60, i).getContents());
cigarette.setStatus(se.getCell(61, i).getContents());
cigarette.setIsBreed(se.getCell(62, i).getContents());
cigarette.setIsCollectStore(se.getCell(63, i).getContents());
cigarette.setIsCollectPri(se.getCell(64, i).getContents());
cigarette.setOutDate(se.getCell(65, i).getContents());
cigarette.setPri(se.getCell(66, i).getContents());
cigarette.setPri3(se.getCell(67, i).getContents());
cigarette.setRsn(se.getCell(68, i).getContents());
cigarette.setIsCtlWhse(se.getCell(69, i).getContents());
cigarette.setPlans(se.getCell(70, i).getContents());
cigarette.setForeQty(se.getCell(71, i).getContents());
cigarette.setComId(se.getCell(72, i).getContents());
cigarette.setFuserName(se.getCell(73, i).getContents());
cigaretteDAO.attachDirty(cigarette);
}
book.close();
} catch (Exception e) {
e.printStackTrace();
}
}
错误原因:
Cigarette cigarette = new Cigarette();初始化的位置错误。
由于在一个事务中更新了主键,而主键是不能被更新的.
这句代码放在for循环的外面,因此每次循环插入的时候,Hibernate认为只是一个对象,主键被更新,因此报错,如果放在for循环里面,就正常了,每次插入都是一个新的对象.
修改:
将放在for循环里面
for(int i=1;i<rownum;i++){
Cigarette cigarette = new Cigarette();
System.out.println(i);
cigarette.setPkId(Integer.parseInt(se.getCell(0, i).getContents()));
cigarette.setItemCode(se.getCell(1, i).getContents());
分享到:
相关推荐
报错误error C2065: '_beginthreadex' :undeclared identifier
Keil MDK 编译 ucOS-II 出现的警告和错误解决
The Digital Object Identifier initiative: metadata implications Context/status information The purpose of this document is to generate a DOI Foundation consensus paper on metadata, as a companion ...
本文介绍Oralce数据库中,表名可以使用的最大长度。这个长度也是Oracle...*Cause: An identifier with more than 30 characters was specified. *Action: Specify at most 30 characters. 从这个错误提示可以看出
Java实现标识符对类的访问控制代码Java implementation of access control identifier code of the class
在使用AD运行Ultra Librarian脚本UL_Import.pas时,低版本的Altium Designer可能会遇到错误:Undeclared identifier:GetCurrentProductBuild。 这时,点击OK,再点击停止按钮。 使用{}将出现错误的地方注释掉,...
Keil C编译器常见警告与错误信息的解决方法 1. Warning 280:’i’:unreferenced local variable 说明 局部变量 i 在函数中未作任何的存取操作 解决方法 消除函数中 i变量的宣告 2 Warning 206:’Music3’:missing ...
CPU-Identifier, 检查你的A9芯片制造商 CPU标识符这个小应用程序可以检测你的iPhone的CPU芯片组。 对于 iPhone/6s,它还可以检测到A9芯片的制造商。编译的( 签名) 二进制文件将把芯片模型。设备模型和一个惟一 id ( ...
PEiD(PE Identifier)是一款著名的查壳工具,其功能强大,几乎可以侦测出所有的壳,其数量已超过470 种PE 文档 的加壳类型和签名。
没有人会否认ORACLE是全球最有影响的数据库产品之一...不过好的东西似乎总不是那么好用(初看起来如此),甚至有些无情--总会给layman们一个个无情的错误号。下面是我个人的总结,条条有用,希望能给初学者一点启示。
一款辅助进行病毒分析的工具,它包括各种文件格式识别功能,使用超级巡警的格式识别引擎,集查壳、虚拟机脱壳、PE文件编辑、PE文件重建、导入表抓取(内置虚拟机解密某些加密导入表)、进程内存查看/DUMP、附加数据...
KB2558 Desigo CC 2.1 SR1, ABT-Pro, XWP: Lease time of S7DOS expired at 31.12.2015 https://support.industry.siemens.com/cs/us/en/view/109482349
1. A practical approach to motion generation and control for an omnidirectional mobile robot Paromtchik, I.E.; Rembold, U. Robotics and Automation, 1994. Proceedings., 1994 IEEE International ...
本文档主要讲述了Keil C编译器常见警告与错误信息的解决方法
一款辅助进行病毒分析的工具,它包括各种文件格式识别功能,使用超级巡警的格式识别引擎,集查壳、虚拟机脱壳、PE文件编辑、PE文件重建、导入表抓取(内置虚拟机解密某些加密导入表)、进程内存查看/DUMP、附加数据...
SET QUOTED_IDENTIFIER ON GO SET ANSI_NULLS ON GO ALTER PROCEDURE test @From varchar(100)="zhang.zhanling@itgemini.net" , @To varchar(100)="zhang.zhanling@itgemini.net" ,@eng varchar(1000)=" ", ...
Microsoft OLE DB Provider for ODBC Drivers 错误'80040e4d'[Oracle][ODBC][Ora]ORA-12154: TNS:could not resolve the connect identifier specified. 使用PL-SQL Developer能连接上Oracle,但是ASP+ODBC连不上...
VC++编程中,20种常见的编译错误信息以及解决方案
大成天下-数据安全实验室(DSW LABS) 出品 File Format Identifier(超级巡警病毒分析工具是一款辅助进行病毒分析的工具,它包括各种文件格式识别功能,使用超级巡警的格式识别引擎,集查壳、虚拟机脱壳、PE文件编辑、...
USE_NATIVE_EH has an invalid value, change it to 1. error C2065: ‘_bstr_t’ : undeclared identifier error MSB8008: 指定的平台工具集(v110)未安装或无效 error C2065: “CString”: 未声明的标识符 error...