`
lg_aku
  • 浏览: 48033 次
  • 性别: Icon_minigender_1
  • 来自: 青岛
文章分类
社区版块
存档分类
最新评论

identifier of an instance of Object is altered from 2 to 5

阅读更多
Hibernate的提示错误
Caused by: org.hibernate.HibernateException:
identifier of an instance of ... is alterde from 1 to 5

是下面这段代码报的错
public void insertRelation(Object obj,List list1)
	{
		Object obj= new Object ();

		for (int i = 0; i < list1.size(); i++) 
		{
		   service.insert(obj);
		}
		
	}



这个错误是由于在一个事务中更新了主键,而主键是不能被更新的.
这段代码的错误在Object obj= new Object ();
这句代码放在for循环的外面,因此每次循环插入的时候,Hibernate认为只是一个对象,主键被更新,因此报错,如果放在for循环里面,就正常了,每次插入都是一个新的对象.
正确的代码如下

public void insertRelation(Object obj,List list1)
	{
		
		for (int i = 0; i < list1.size(); i++) 
		{
                      Object obj= new Object ();

		    service.insert(obj);
		}
		
	}
分享到:
评论
1 楼 cl1154781231 2011-01-28  
学习了!
原来是因为
一个事务中更新了主键,而主键是不能被更新的.

相关推荐

    FlexGraphics_V_1.79_D4-XE10.2_Downloadly.ir

    - ADD: Add TFlexPanel.InvalidateControl virtual method which calls from TFlexControl.Invalidate and can be overriden (it is possible now to catch all object invalidation calls). - FIX: The TFlexPanel....

    The Digital Object Identifier initiative: metadata implications

    数字对象标识符(Digital Object Identifier,简称DOI)是一种持久性标识符,用于唯一地标识数字资源,如学术文章、数据集等。DOI系统由国际DOI基金会管理,并在出版界广泛采用。随着数字资源的增加以及对资源描述的...

    servlet2.4doc

    A FilterChain is an object provided by the servlet container to the developer giving a view into the invocation chain of a filtered request for a resource. FilterConfig - interface javax.servlet....

    park an autonomous vehicle

    This research work is carried out within the framework of the PRAXITELE project which aims to develop a future-oriented urban transportation system based on a fleet of electric computer-driven ...

    微软内部资料-SQL性能优化3

    An isolation level determines the degree to which data is isolated for use by one process and guarded against interference from other processes. Prior to SQL Server 7.0, REPEATABLE READ and ...

    VclZip pro v3.10.1

    If you currently work with VCLZip 2.X with TBlobStreams or some other type of streams, you can either define your own TkpBlobStream for instance which inherits from TkpHugeStream, or use the ...

    Devart LinqConnect 3.1

    The "Identifier Case Sensitive" check box, which enables case-sensitive processing of database object identifier names, is added to MySQL Server Options The documentation generation for Enum members ...

    微软内部资料-SQL性能优化5

    Each index row in node pages contains an index key (or set of keys for a composite index) and a pointer to a page at the next level for which the first key value is the same as the key value in the ...

    计算机网络第六版答案

    Wifi (802.11) In a wireless LAN, wireless users transmit/receive packets to/from an base station (i.e., wireless access point) within a radius of few tens of meters. The base station is typically ...

    eac3to V3.17

    * when demuxing subtitle files, the number of captions is added to the filename * timestamp derived FPS is used for gap checking instead of video bitstream FPS * fixed: 44.1khz AC3 encoding was still ...

    Odoo 11 Development Essentials 3 Edition(epub)

    Chapter 5, Import, Export, and Module Data, covers the most used Odoo data file formats—XML and CSV—the external identifier concept, how use to data file in modules, and data import/export ...

    Prototype Cheat Sheet

    - **`extend(event)`**: Extends the functionality of an event object. - **`findElement(event, tagName)`**: Finds the first element under the target of an event that matches the specified `tagName`. -...

    NewSID(光学习一下代码就可以了,没看清楚介绍别运行)

    All resources, including files and Registry keys, that one user has access to, the other will as well.Another instance where duplicate SIDs can cause problems is where there is removable media ...

    Keil MDK 编译 ucOS-II 出现的警告和错误解决

    错误:L6238E:os_cpu_a.o(subr) contains invalid call from '~PRES8 (The user did not require code to preserve 8-byte aligment of 8-byte data objects)' function to 'REQ8 (Codewas permitted to depend on ...

    留学生React Native计算器作业-待视频演示.zip

    The user can enter a number to each of the two textinput boxes, then click/tap either of the four images of mathematical operators. Once clicked, it should display a correct answer on the screen. 1. ...

    1987IEEE Guide for Control of Hydroelectric Power Plants

    1987IEEE Guide for Control of Hydroelectric Power Plants

    aes 加密代码

    2 Octet - Length in octets (in network byte order) of an extension identifier and contents. If 0x0000, then no further extensions exist and the next octet is the start of the Initialization Vector...

Global site tag (gtag.js) - Google Analytics