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

再谈 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
分享到:
评论

相关推荐

    The Digital Object Identifier initiative: metadata implications

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

    计算机网络第六版答案

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

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

    A Novel RFID Authentication Protocol with Ownership Transfer.doc

    The major contribution of this paper is to present a novel security and privacy RFID method with group ownership transfer. This protocol involves minimal interaction between reader and tags. The ...

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

    a_byte_of_python

    this is a book about python. it was written by Swaroop C H.its name is "a byte of python". Table of Contents Preface Who This Book Is For History Lesson Status of the book Official Website ...

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

    Odoo 11 Development Essentials 3 Edition(epub)

    Chapter 4, Models – Structuring the Application Data, discusses the Model layer in detail, introducing the framework's Object-Relational Mapping (ORM), the different types of models available, and ...

Global site tag (gtag.js) - Google Analytics