工程中存在报错a different object with the same identifier value was already associated with the session
研究过程中发现
1.保存对象失败
2.事务没有回滚
源码:
equipmentDao.delGroupInfoDtls(delList);//成功执行
equipmentDao.saveGroupInfoDtlList(addList);//执行失败,不确定异常是否和a different object with the same identifier value was already associated with the session 有关。
保存失败:
怀疑原因
典型原因
事务没有回滚
怀疑原因
1.因为抛出的异常不是RuntimException类型,所有没有执行回滚
2.因为struts-config.xml文件也出现了配置的问题,导致OpenSessioInView失效
来源http://blog.sina.com.cn/s/blog_5ca9fdd80100ffor.html
Hibernate 疑难异常及处理
1、a different object with the same identifier value was already associated with the session。
错误原因:在hibernate中同一个session里面有了两个相同标识但是是不同实体。
解决方法一:session.clean()
PS:如果在clean操作后面又进行了saveOrUpdate(object)等改变数据状态的操作,有可能会报出"Found two representations of same collection"异常。
解决方法二:session.refresh(object)
PS:当object不是数据库中已有数据的对象的时候,不能使用session.refresh(object)因为该方法是从hibernate的 session中去重新取object,如果session中没有这个对象,则会报错所以当你使用saveOrUpdate(object)之前还需要判断一下。
解决方法三:session.merge(object)
PS:Hibernate里面自带的方法,推荐使用。
2、Found two representations of same collection
错误原因:见1。
解决方法:session.merge(object)
以上两中异常经常出现在一对多映射和多对多映射中
a different object with the same identifier value was already associated with the session
一个经典的hibernate错误:a different object with the same identifier value was already associated with the session xxxx
hibernate3.0以上使用merge()来合并两个session中的同一对象
http://www.iteye.com/topic/15057?page=1
我原来用struts/spring/hibernate的时候同样使用OpenSessionInView,但是似乎没有robbin所说的问题啊。而且我在使用的时候,是ContextLoaderListener和ContextLoaderPlugIn一起用的。整个配置如下:
1.首先是web.xml
Java代码
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
.....
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
......
2. 然后是struts-config.xml:
Java代码
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/action-servlet.xml"
/>
</plug-in>
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/action-servlet.xml"
/>
</plug-in>
分享到:
相关推荐
1.将sqlite3.exe放到.svn的同级目录 2.启动cmd执行sqlite3 .svn/wc.db 3. "select * from work_queue"; 4. delete from work_queue; 5.svn目录下右键:TortoiseSVN->Clean up
AAMI TIR42:2021 Evaluation of particulate associated with vascul
F. C. Fishburn, Mean-risk analysis with risk associated with below-target returns, Amer. Econoc. Rev., 67(1977), pp. 116-126.
it contains all the MATLAB demo code associated with my machine learning notes
it contains all the MATLAB demo code associated with my machine learning notes
Firstly, unlike the classical Wigner-Ville transform, a new definition of Wigner-Ville distribution associated with the linear canonical transform is given. Then, the main properties of the
viii SIP: Understanding the Session Initiation Protocol 4 SIP Request Messages 71 4.1 Methods 71 4.1.1 INVITE 72 4.1.2 REGISTER 74 4.1.3 BYE 76 4.1.4 ACK 77 4.1.5 CANCEL 79 4.1.6 OPTIONS 81 4.1.7 ...
与Schrodinger算子相关的Riesz变换交换子的端点估计,李澎涛,彭立中,本文我们主要考虑与Schr{o}dinger 算子L=-△+V相关的Riesz 变换交换子的H1L (Rn)有界性, 其中 H1L (Rn)是与$L$相关的Hardy 空间. 我们假定 V ...
ESR1多态性与中国汉族人群乳腺癌易感性的关联研究,杨学习,李欣,为了探讨ESR1单核苷酸多态性与中国汉族人群乳腺癌易感性的关系,通过Sequenom MassArray? iPLEX平台对845例乳腺癌病人和882例健康对照进行了�
文献,希望能帮助需要次文献的人dietary folate alters the mouse sperm epigenome and is associated with.pdf
具有随机保费的风险模型下的平均折现罚金函数 ,汪荣明,姚定俊,本文考虑随机保费的风险模型下平均折现罚金函数。与经典的风险模型相比较保费过程不再是线性过程,总保费过程构成一复合Poisson过�
血浆Apelin水平与血压升高相关,李昭,白英龙,目的Apelin是G蛋白受体APJ的内源性配体,有研究报告Apelin与心血管系统密切相关包括参与心肌收缩性的调节。本研究的目的是探求血浆Apelin�
线性弹性最小二乘有限元算子的谱_On the spectrum of an operator associated with least-squares finite elements for linear elasticity.pdf
细胞是一个大的有机组织,它里面有很多的蛋白质,这些蛋白质有很多独特的功能。
银杉落针病的病原--散斑壳属一新种,高小明,林英任,银杉,是中国一级保护物种,被誉为植物界的“活化石”。银杉落针病的病原原先被描述为松针散斑壳,在本文研究中重新鉴定为一新种
The moments associated with the linear canonical transform is investigated. First, the relationship between the Wigner distribution and the linear canonical transform is reviewed, then the moments ...
zero-delay handoff does not scale with the handover frequency. Especially for small radio cell sizes, the overlapping may easily exceed 60% of the cell’s diameter. The improvement gained by ...
No Elf file associated with target 这是vivado2016.4的bug 解决方案: 1.使用system debug 代替 GDB 2.替换xmdterm.tcl 文件: 下载本xmdterm.tcl 资源,然后到你的SDK的安装目录下替换原来的xmdterm.tcl ...
Fundamentals of the JavaMail API Presented by developerWorks, your source for great tutorials ibm.com/developerWorks Table of Contents If you're viewing this document online, you can click ...
Cortactin基因的高表达与前列腺癌侵袭性及转移的关系,马鹏德,盛镔,远处转移是前列腺癌患者死亡的主要原因,Cortactin蛋白已被证实在癌细胞的侵袭和迁移过程中是非常必要的,而且在肿瘤细胞的远处转移