`
likenice
  • 浏览: 62198 次
  • 来自: 北京
社区版块
存档分类
最新评论

再谈 a different object with the same identifier val

阅读更多

a different object with the same identifier value was already associated with the session


刚才自己调试程序时出现这个异常。
后来google 百度都说是session.clean()一下。而我的问题与这个不同,虽然抛出的异常相同。
现在解决了。做个记录,如果有和我相同问题的人希望对其有所帮助。

问题原因:我有两个表,wp和zjyj。(物品表 和 专家意见表)
这两个表的关系是 zjyj 和 wp 是多对一的关系。
我在增加物品同时需要对 专家意见表中建立一条只有 id 和 wpid 的记录。所以我开始的代码是
IWpService service = (IWpService) BeanUtil.getBean("wpService");
Wp wp = new Wp();
wp.setStatus(1);
Zjyj zjyj = new Zjyj();
zjyj.setWp(wp);
service.saveWp(wp);// 保存物品
这样目的是将wp和zjyj的表内容填写完毕后直接保存。
可是其中没有注意到wp表在没有保存是id是不能确定的。

所以应该改成下面
IWpService service = (IWpService) BeanUtil.getBean("wpService");
Wp wp = new Wp();
wp.setStatus(1);
service.saveWp(wp);// 保存物品
Zjyj zjyj = new Zjyj();
IZjyjDao zjyjDao = (IZjyjDao) BeanUtil.getBean("zjyjService");
zjyj.setWp(wp);
zjyjDao.save(zjyj);
大家可以断点测试一下。会发现。
在wp保存了后,wp对象中的wpid就赋值了。
接下来在保存zjyj。就没有问题。

 

 

1
0
分享到:
评论

相关推荐

    hibernate常见异常

    a different object with the same identifier value was already associated with the session 是一种常见的异常,通常是由于在 Hibernate 中同一个 session 里面有了两个相同标识但是是不同实体所致。解决方案有...

    The Digital Object Identifier initiative: metadata implications

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

    计算机网络第六版答案

    In these systems, packets are transmitted over the same wireless infrastructure used for cellular telephony, with the base station thus being managed by a telecommunications provider. This provides ...

    FlexGraphics_V_1.79_D4-XE10.2_Downloadly.ir

    - FIX: The height of the TFlexRegularPolygon object incorrectly changes with its rotation. - FIX: Added division by zero protect in method TFlexControl.MovePathSegment. - FIX: The background beyond ...

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

    A clustered index is like a telephone directory in which all of the rows for customers with the same last name are clustered together in the same part of the book. Just as the organization of a ...

    developing android application with adobe air.part3.rar

    EXIF Data and the Map Object The speed Property Conclusion Chapter 11 : Microphone and Audio The Microphone Audio Assets Working with Sounds ID3 Tags Modifying Sound Raw Data and the Sound Spectrum ...

    S7A驱动720版本

    - The driver can now be registered as a service with the local system account as the log-on account. For more information see the document "S7A_as_Service.PDF" on the installation CD . - The ...

    hibernate常见问题及处理.doc

    5. `a different object with the same identifier value was already associated with the session` 这个异常表明在同一个Hibernate Session中存在两个具有相同标识但实际是不同对象的情况。处理方法有: - 使用`...

    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 ...

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

    Note that just changing the computer name or adding the computer to a different domain does not change the computer SID and that the computer SID is not the same as the SID, called the domain SID, ...

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

    Another type of table lock is a schema stability lock (Sch-S) and is compatible with all table locks except the schema modification lock (Sch-M). The schema modification lock (Sch-M) is incompatible ...

    windows程序设计

    created with the default settings in Microsoft Visual C++ 6 with one major exception: aside from other compiler and linker flags, the executable in the DEBUG directory has been compiled with the ...

    高性能消息传输机制Aeron.zip

    two and must be the same length on both ends.Term ID: A unique identifier for a Term within a Stream. Starts randomly. Must increase monotonically. Can wrap around. Can not go back to a wrapped ...

    VclZip pro v3.10.1

    This was due to a problem where it would be freed automatically if there was a problem with the ArchiveStream when trying to open it as a zip file (possibly corrupt). Best practice is that ...

    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....

    libtomcrypt-1.17

    LibTomCrypt is a fairly comprehensive, modular and portable cryptographic toolkit that provides developers with a vast array of well known published block ciphers, one-way hash functions, chaining ...

    Hibernate Tutorial 03 (Object Identifier).pdf

    在本教程中,我们将深入探讨Hibernate框架中的一个核心概念——对象标识符(Object Identifier)。通过本篇教程的学习,您将了解到对象标识符在Hibernate中的重要性以及如何正确地为持久化对象设置标识符。此外,我们...

    park an autonomous vehicle

    Real-time path generation is based on the polynomial spline-interpolation with prediction of velocities of a spline-function. The mobile vehicle control is performed with the use of its kinematic ...

    CAN Specification Version 2.0

    CAN SpecificationVersion 2.0。The acceptance and introduction of serial communication to more and more ...so that messages in standard format and extended format can coexist within the same network.

    不常用的TParser类解析(文本文件中相关字符串)

    Checks whether the current token is a component identifier. function TokenFloat; Returns the current token as a float. function TokenInt; Returns the current token as an integer function Token...

Global site tag (gtag.js) - Google Analytics