`
- 浏览:
438123 次
- 性别:
- 来自:
北京
-
identifier of an instance of Object is altered from 2 to 5 .
HibernateJava
Hibernate的提示错误
Caused by: org.hibernate.HibernateException:
identifier of an instance of ... is alterde from 1 to 5
是下面这段代码报的错
Java代码
01.public void insertRelation(Object obj,List list1)
02. {
03. Object obj= new Object ();
04.
05. for (int i = 0; i < list1.size(); i++)
06. {
07. service.insert(obj);
08. }
09.
10. }
01.public void insertRelation(Object obj,List list1)
02. {
03. Object obj= new Object ();
04.
05. for (int i = 0; i < list1.size(); i++)
06. {
07. service.insert(obj);
08. }
09.
10. }
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循环里面,就正常了,每次插入都是一个新的对象.
正确的代码如下
Java代码 01.
02.public void insertRelation(Object obj,List list1)
03. {
04.
05. for (int i = 0; i < list1.size(); i++)
06. {
07. Object obj= new Object ();
08.
09. service.insert(obj);
10. }
11.
12. }
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
- 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 Way to Go,: A Thorough Introduction to the Go Programming Language 英文书籍,已Cross the wall,从Google获得书中源代码,分享一下。喜欢请购买正版。 目录如下: Contents Preface......................
数字对象标识符(Digital Object Identifier,简称DOI)是一种持久性标识符,用于唯一地标识数字资源,如学术文章、数据集等。DOI系统由国际DOI基金会管理,并在出版界广泛采用。随着数字资源的增加以及对资源描述的...
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....
1.1.1 Performance and Mobility Management related Issues..............2 1.1.2 Architecture related Issues..........................................................4 1.1.3 Procedure and Radio related ...
1.1.1 Performance and Mobility Management related Issues..............2 1.1.2 Architecture related Issues..........................................................4 1.1.3 Procedure and Radio related ...
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 ...
标题和描述中提到的"PC-IDENTIFIER-**.**.**.**-**.**.**.**安装包-链接地址.txt"和"PC_IDENTIFIER_**.**.**.**_**.**.**.**安装包_链接地址"是文件的名称和描述,它们所指的知识点是关于一个特定版本的软件或插件的...
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 ...
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 ...
1.1.1 Performance and Mobility Management related Issues..............2 1.1.2 Architecture related Issues..........................................................4 1.1.3 Procedure and Radio related ...
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 ...
23.4.2. Composite key example 23.4.3. Many-to-many with shared composite key attribute 23.4.4. Content based discrimination 23.4.5. Associations on alternate keys 24. Best Practices
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
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 ...
`canal.instance.gtidon`参数用于启用或禁用GTID(Global Transaction Identifier)模式。GTID是MySQL的一种事务跟踪机制,如果启用,Canal将使用GTID来定位和跟踪数据库中的事务。在这个示例中,该值被设置为`false...