`
liutjedu
  • 浏览: 46645 次
  • 性别: Icon_minigender_1
  • 来自: 天津
最近访客 更多访客>>
社区版块
存档分类
最新评论

老生常谈的session的问题

阅读更多

目前的结构采用的是Struts+spring+hibernate,目前遇到一个问题,Riskdutyfactor表与riskDuty是多对多的关系,中间表为factorRiskDuty

配置文件如下:

RISKDUTY表:

xml 代码
  1. <hibernate-mapping>  
  2.     <class name="com.sleb.po.Riskduty" table="RISKDUTY" schema="XFLIU">  
  3.         <id name="riskdutyid" type="integer">  
  4.             <column name="RISKDUTYID" />  
  5.             <generator class="sequence" >  
  6.             <param name="sequence">S_RISKDUTY</param>  
  7.             </generator>  
  8.         </id>  
  9. .....   
  10.         <set name="riskdutyrisks" inverse="true">  
  11.             <key>  
  12.                 <column name="RISKDUTYID" />  
  13.             </key>  
  14.             <one-to-many class="com.sleb.po.Riskdutyrisk" />  
  15.         </set>  
  16.         <!-- 设计责任和责任要素的多对多的关联,手动修改过,中间表名称为FACTORRISKDUTY-->  
  17.         <set name="riskdutyfactors" table="FACTORRISKDUTY" cascade="save-update">  
  18.             <key>  
  19.                 <column name="RISKDUTYID" />  
  20.             </key>  
  21.             <many-to-many class="com.sleb.po.Riskdutyfactor" column="RISKDUTYFACTORID" />  
  22.         </set>  
  23.     </class>  
  24. </hibernate-mapping>  


------------------------

riskdutyfactor表映射文件: ----------先对以上进行解释,有一个界面是用来增加RISKDUTYFACTOR表中的数据的,另一个界面用来增加RISKDUTY数据的,在增加RISKDUTY的时候,需要使用RISKDUTYFACTOR表中的数据,由于是多对多的关系,因此增加FACTORRISKDUTY中间表.由以上可以知道riskduty增加的时候,再对中间表进行更新,因此设置RISKDUTY配置文件中的cascade="save-update"> 来维护关系,我想这个是正确的,因为我能正确的增加数据.RiskDutyService程序如下:
  

  1. // 保存一个责任要素   
  2. public boolean saveRiskduty(String dutyName, String dutyType,   
  3.   String[] baseChecked, String[] complexChecked) {     
  4.  riskDuty.setDutyname(dutyName);   
  5.  riskDuty.setDutytype(dutyType);   
  6.  if (baseChecked != null) {   
  7.   for (int i = 0; i < baseChecked.length; i++) {   
  8.    log.info(this.getRiskDutyFactorByPk(new Integer(baseChecked[i])).getFactorname());   
  9.    //首先根据页面上请求的ID,取得RiskDutyFactor对象,后与RiskDuty关联   
  10.    riskDuty.getRiskdutyfactors().add(this.getRiskDutyFactorByPk(new Integer(baseChecked[i])));       
  11.   }   
  12.  }   
  13.  if (complexChecked != null) {   
  14.   for (int i = 0; i < complexChecked.length; i++) {   
  15.    log.info(this.getRiskDutyFactorByPk(new Integer(complexChecked[i])).getFactorname());   
  16. /    首先根据页面上请求的ID,取得RiskDutyFactor对象,后与RiskDuty关联   
  17.    riskDuty.getRiskdutyfactors().add(this.getRiskDutyFactorByPk(new Integer(complexChecked[i])));   
  18.   }   
  19.  }   
  20.  log.info("begin save complexCheck riskDuty");   
  21.  this.getRiskDutyDAO().save(riskDuty);   
  22.   
  23.  bl=true;   
  24.  //this.getRiskDutyFactorDAO().getCurrentSession().clear();   
  25.     
  26.  return bl;   
  27. }   

第一次增加riskduty是没有任何问题的,但是第2次的时候,报如下错误:org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.sleb.po.Riskdutyfactor#1]

----------我知道出现的问题是在this.getRiskDutyFactorByPk(new Integer(baseChecked[i])));    但是在网上找了很对解决办法,都没有实现,比较纳闷,所以写在自己的BLOG中,请看看怎么修改.

this.getRiskDutyFactorByPk(new Integer(baseChecked[i])));   对它也进行说明,我们是在riskDutyService中增加了

 //根据责任要素主键,取得一个责任要素对象,该方法避免了service调用service是的事务调用事务的问题
 public Riskdutyfactor getRiskDutyFactorByPk(Integer id) {
   return (Riskdutyfactor)this.getRiskDutyFactorDAO().getByPk(Riskdutyfactor.class,id);
 }

方法直接调用RiskDutyFactorDAO中的方法,这样做的目的是避免了使用riskDutyService调用riskDutyFactorService.因此spring 中的配置文件修改为:
 <!---->
 请教高手!

xml 代码

<bean id="riskDutyService" parent="proxyTemplate"></bean>

  1. <!--riskDuty service -->  
  2.     <bean id="riskDutyService" parent="proxyTemplate">  
  3.         <property name="target">  
  4.             <bean class="com.sleb.service.riskDuty.spring.RiskDutyServiceImpl">  
  5.                 <property name="riskDutyDAO">  
  6.                     <ref local="riskDutyDAO" />  
  7.                 </property>  
  8.                 <property name="riskDutyFactorDAO">  
  9.                     <ref local="riskDutyFactorDAO" />  
  10.                 </property>  
  11.             </bean>  
  12.         </property>  
  13.     </bean>  
  14.     <bean id="riskDutyDAO" class="com.sleb.dao.riskDuty.RiskDutyDAOImpl">  
  15.         <property name="sessionFactory">  
  16.             <ref bean="sessionFactory" />  
  17.         </property>  
  18.     </bean>  

 

xml 代码
  1. <hibernate-mapping>  
  2.     <class name="com.sleb.po.Riskdutyfactor" table="RISKDUTYFACTOR" schema="XFLIU">  
  3.         <id name="riskdutyfactorid" type="integer">  
  4.             <column name="RISKDUTYFACTORID" />  
  5.             <generator class="sequence" >  
  6.             <param name="sequence">S_RISKDUTYFACTOR</param>  
  7.             </generator>  
  8.         </id>  
  9.         <property name="factorname" type="string">  
  10.             <column name="FACTORNAME" length="20" />  
  11.         </property>  
  12.         <property name="factorunit" type="string">  
  13.             <column name="FACTORUNIT" length="120" />  
  14.         </property>  
  15.         <property name="value" type="string">  
  16.             <column name="VALUE" length="120" />  
  17.         </property>  
  18.         <property name="sign" type="string">  
  19.             <column name="SIGN" length="1" />  
  20.         </property>  
  21.         <property name="language" type="string">  
  22.             <column name="LANGUAGE" length="1" />  
  23.         </property>  
  24.         <!-- 设计责任要素和责任的多对多的关联,手动修改过,中间表名称为FACTORRISKDUTY-->  
  25.         <set name="riskduties" table="FACTORRISKDUTY"  inverse="true" cascade="none">  
  26.             <key>  
  27.                 <column name="RISKDUTYFACTORID" />  
  28.             </key>  
  29.             <many-to-many class="com.sleb.po.Riskduty" column="RISKDUTYID" />  
  30.         </set>  
  31.     </class>  
  32. </hibernate-mapping>  


<hibernate-mapping></hibernate-mapping>

java 代码
分享到:
评论
21 楼 liutjedu 2007-02-27  
to janh:
    我在第一次操作的时候,可以增加的,但是等第2次操作的时候,就报以上错误.也就是不可能是你提到的一次处理过程中出现了多个session.

哪位大哥,可以给帮忙调试下,已经好久了,都弄不明白.谢谢!
20 楼 janh 2007-02-27  
问题应该出在session的管理上,在一次处理过程中出现了多个session,或者用到了上一处理过程中留下来的对象,自己去调试吧。
19 楼 liutjedu 2007-02-26  
大家还在过年吗?呵呵!
18 楼 liutjedu 2007-02-25  
1.数据库目前为DB2 8.2
2.执行sleb/crebas_db2.sql里的sql,生成数据库表
3.部署后先执行http://10.156.4.31:8090/sleb/riskDutyFactor/saveRiskDutyFactor.jsp,添加几个内容,后执行
http://10.156.4.31:8090/sleb/riskDuty/saveRiskDutyLink.jsp,点查询,后任意增加几个内容。第一次增加的时候不会报错,第2次就会出现错误。
所有日志如下:

13:22:14,061 INFO  [PropertyMessageResources] Initializing, config='org.apache.struts.taglib.bean.LocalStrings', returnNull=true
13:22:14,139 INFO  [PropertyMessageResources] Initializing, config='org.apache.struts.util.LocalStrings', returnNull=true
13:22:14,139 INFO  [PropertyMessageResources] Initializing, config='org.apache.struts.taglib.html.LocalStrings', returnNull=true
13:22:14,155 INFO  [PropertyMessageResources] Initializing, config='org.apache.struts.taglib.html.LocalStrings', returnNull=true
13:22:14,155 INFO  [PropertyMessageResources] Initializing, config='org.apache.struts.taglib.html.LocalStrings', returnNull=true
13:22:14,155 INFO  [PropertyMessageResources] Initializing, config='org.apache.struts.taglib.html.LocalStrings', returnNull=true
13:22:14,217 INFO  [PropertyMessageResources] Initializing, config='org.apache.struts.taglib.html.LocalStrings', returnNull=true
13:22:14,217 INFO  [PropertyMessageResources] Initializing, config='org.apache.struts.taglib.html.LocalStrings', returnNull=true
13:22:14,217 INFO  [PropertyMessageResources] Initializing, config='org.apache.struts.taglib.html.LocalStrings', returnNull=true
13:22:14,217 INFO  [PropertyMessageResources] Initializing, config='org.apache.struts.taglib.html.LocalStrings', returnNull=true
13:22:24,226 INFO  [PropertyMessageResources] Initializing, config='org.apache.struts.actions.LocalStrings', returnNull=true
13:22:24,336 INFO  [JdbcTransactionObjectSupport] JDBC 3.0 Savepoint class is available
13:22:24,508 INFO  [XmlBeanDefinitionReader] Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
13:22:24,570 INFO  [SQLErrorCodesFactory] SQLErrorCodes loaded: [DB2, HSQL, MS-SQL, MySQL, Oracle, Informix, PostgreSQL, Sybase]
13:22:24,820 INFO  [STDOUT] Hibernate: select count(*) as col_0_0_ from XFLIU.RISKDUTYFACTOR riskdutyfa0_ where (riskdutyfa0_.FACTORNAME='保险期间' )
13:22:25,038 INFO  [STDOUT] Hibernate: values nextval for S_RISKDUTYFACTOR
13:22:25,241 INFO  [RiskDutyFactorDAOImpl] save successful
13:22:25,241 INFO  [STDOUT] Hibernate: values nextval for S_RISKDUTYFACTOR
13:22:25,241 INFO  [RiskDutyFactorDAOImpl] save successful
13:22:25,241 INFO  [STDOUT] Hibernate: values nextval for S_RISKDUTYFACTOR
13:22:25,241 INFO  [RiskDutyFactorDAOImpl] save successful
13:22:25,304 INFO  [STDOUT] Hibernate: insert into XFLIU.RISKDUTYFACTOR (FACTORNAME, FACTORUNIT, VALUE, SIGN, LANGUAGE, RISKDUTYFACTORID) values (?, ?, ?, ?, ?, ?)
13:22:25,319 INFO  [STDOUT] Hibernate: insert into XFLIU.RISKDUTYFACTOR (FACTORNAME, FACTORUNIT, VALUE, SIGN, LANGUAGE, RISKDUTYFACTORID) values (?, ?, ?, ?, ?, ?)
13:22:25,319 INFO  [STDOUT] Hibernate: insert into XFLIU.RISKDUTYFACTOR (FACTORNAME, FACTORUNIT, VALUE, SIGN, LANGUAGE, RISKDUTYFACTORID) values (?, ?, ?, ?, ?, ?)
13:22:25,757 INFO  [PropertyMessageResources] Initializing, config='org.apache.struts.taglib.bean.LocalStrings', returnNull=true
13:23:05,106 INFO  [SaveRiskDutyFactorForm] factorUnitStr.length and factotValueStr.length are 0
13:23:05,121 INFO  [STDOUT] Hibernate: select count(*) as col_0_0_ from XFLIU.RISKDUTYFACTOR riskdutyfa0_ where (riskdutyfa0_.FACTORNAME='费率' )
13:23:05,121 INFO  [STDOUT] Hibernate: values nextval for S_RISKDUTYFACTOR
13:23:05,121 INFO  [RiskDutyFactorDAOImpl] save successful
13:23:05,121 INFO  [STDOUT] Hibernate: insert into XFLIU.RISKDUTYFACTOR (FACTORNAME, FACTORUNIT, VALUE, SIGN, LANGUAGE, RISKDUTYFACTORID) values (?, ?, ?, ?, ?, ?)
13:23:12,304 INFO  [SaveRiskDutyFactorForm] factotValueStr.length is 0
13:23:12,335 INFO  [STDOUT] Hibernate: select count(*) as col_0_0_ from XFLIU.RISKDUTYFACTOR riskdutyfa0_ where (riskdutyfa0_.FACTORNAME='计算方向' )
13:23:12,335 INFO  [STDOUT] Hibernate: values nextval for S_RISKDUTYFACTOR
13:23:12,335 INFO  [RiskDutyFactorDAOImpl] save successful
13:23:12,335 INFO  [STDOUT] Hibernate: values nextval for S_RISKDUTYFACTOR
13:23:12,351 INFO  [RiskDutyFactorDAOImpl] save successful
13:23:12,351 INFO  [STDOUT] Hibernate: values nextval for S_RISKDUTYFACTOR
13:23:12,351 INFO  [RiskDutyFactorDAOImpl] save successful
13:23:12,351 INFO  [STDOUT] Hibernate: values nextval for S_RISKDUTYFACTOR
13:23:12,351 INFO  [RiskDutyFactorDAOImpl] save successful
13:23:12,367 INFO  [STDOUT] Hibernate: insert into XFLIU.RISKDUTYFACTOR (FACTORNAME, FACTORUNIT, VALUE, SIGN, LANGUAGE, RISKDUTYFACTORID) values (?, ?, ?, ?, ?, ?)
13:23:12,367 INFO  [STDOUT] Hibernate: insert into XFLIU.RISKDUTYFACTOR (FACTORNAME, FACTORUNIT, VALUE, SIGN, LANGUAGE, RISKDUTYFACTORID) values (?, ?, ?, ?, ?, ?)
13:23:12,367 INFO  [STDOUT] Hibernate: insert into XFLIU.RISKDUTYFACTOR (FACTORNAME, FACTORUNIT, VALUE, SIGN, LANGUAGE, RISKDUTYFACTORID) values (?, ?, ?, ?, ?, ?)
13:23:12,382 INFO  [STDOUT] Hibernate: insert into XFLIU.RISKDUTYFACTOR (FACTORNAME, FACTORUNIT, VALUE, SIGN, LANGUAGE, RISKDUTYFACTORID) values (?, ?, ?, ?, ?, ?)
13:23:16,942 INFO  [SaveRiskDutyFactorForm] factorUnitStr.length and factotValueStr.length are 0
13:23:16,957 INFO  [STDOUT] Hibernate: select count(*) as col_0_0_ from XFLIU.RISKDUTYFACTOR riskdutyfa0_ where (riskdutyfa0_.FACTORNAME='免赔额' )
13:23:16,973 INFO  [STDOUT] Hibernate: values nextval for S_RISKDUTYFACTOR
13:23:16,973 INFO  [RiskDutyFactorDAOImpl] save successful
13:23:16,973 INFO  [STDOUT] Hibernate: insert into XFLIU.RISKDUTYFACTOR (FACTORNAME, FACTORUNIT, VALUE, SIGN, LANGUAGE, RISKDUTYFACTORID) values (?, ?, ?, ?, ?, ?)
13:23:20,830 INFO  [SaveRiskDutyFactorForm] factorUnitStr.length and factotValueStr.length are 0
13:23:20,861 INFO  [STDOUT] Hibernate: select count(*) as col_0_0_ from XFLIU.RISKDUTYFACTOR riskdutyfa0_ where (riskdutyfa0_.FACTORNAME='赔付比例' )
13:23:20,861 INFO  [STDOUT] Hibernate: values nextval for S_RISKDUTYFACTOR
13:23:20,861 INFO  [RiskDutyFactorDAOImpl] save successful
13:23:20,877 INFO  [STDOUT] Hibernate: insert into XFLIU.RISKDUTYFACTOR (FACTORNAME, FACTORUNIT, VALUE, SIGN, LANGUAGE, RISKDUTYFACTORID) values (?, ?, ?, ?, ?, ?)
13:23:26,248 INFO  [SaveRiskDutyFactorForm] factorUnitStr.length and factotValueStr.length are 0
13:23:26,279 INFO  [STDOUT] Hibernate: select count(*) as col_0_0_ from XFLIU.RISKDUTYFACTOR riskdutyfa0_ where (riskdutyfa0_.FACTORNAME='住院期间' )
13:23:26,279 INFO  [STDOUT] Hibernate: values nextval for S_RISKDUTYFACTOR
13:23:26,279 INFO  [RiskDutyFactorDAOImpl] save successful
13:23:26,295 INFO  [STDOUT] Hibernate: insert into XFLIU.RISKDUTYFACTOR (FACTORNAME, FACTORUNIT, VALUE, SIGN, LANGUAGE, RISKDUTYFACTORID) values (?, ?, ?, ?, ?, ?)
13:23:34,867 INFO  [PropertyMessageResources] Initializing, config='org.apache.struts.taglib.logic.LocalStrings', returnNull=true
13:23:36,725 INFO  [PropertyMessageResources] Initializing, config='org.apache.struts.taglib.html.LocalStrings', returnNull=true
13:25:05,542 INFO  [STDOUT] Hibernate: select riskdutyfa0_.RISKDUTYFACTORID as RISKDUTY1_, riskdutyfa0_.FACTORNAME as FACTORNAME0_, riskdutyfa0_.FACTORUNIT as FACTORUNIT0_, riskdutyfa0_.VALUE as VALUE0_, riskdutyfa0_.SIGN as SIGN0_, riskdutyfa0_.LANGUAGE as LANGUAGE0_ from XFLIU.RISKDUTYFACTOR riskdutyfa0_ where (riskdutyfa0_.SIGN='0' )
13:25:05,604 INFO  [STDOUT] Hibernate: select riskdutyfa0_.RISKDUTYFACTORID as RISKDUTY1_, riskdutyfa0_.FACTORNAME as FACTORNAME0_, riskdutyfa0_.FACTORUNIT as FACTORUNIT0_, riskdutyfa0_.VALUE as VALUE0_, riskdutyfa0_.SIGN as SIGN0_, riskdutyfa0_.LANGUAGE as LANGUAGE0_ from XFLIU.RISKDUTYFACTOR riskdutyfa0_ where (riskdutyfa0_.SIGN='0' )
13:25:05,604 INFO  [STDOUT] false
13:25:05,636 INFO  [STDOUT] Hibernate: select riskdutyfa0_.RISKDUTYFACTORID as RISKDUTY1_, riskdutyfa0_.FACTORNAME as FACTORNAME0_, riskdutyfa0_.FACTORUNIT as FACTORUNIT0_, riskdutyfa0_.VALUE as VALUE0_, riskdutyfa0_.SIGN as SIGN0_, riskdutyfa0_.LANGUAGE as LANGUAGE0_ from XFLIU.RISKDUTYFACTOR riskdutyfa0_ where (riskdutyfa0_.SIGN='1' )
13:25:05,667 INFO  [STDOUT] Hibernate: select riskdutyfa0_.RISKDUTYFACTORID as RISKDUTY1_, riskdutyfa0_.FACTORNAME as FACTORNAME0_, riskdutyfa0_.FACTORUNIT as FACTORUNIT0_, riskdutyfa0_.VALUE as VALUE0_, riskdutyfa0_.SIGN as SIGN0_, riskdutyfa0_.LANGUAGE as LANGUAGE0_ from XFLIU.RISKDUTYFACTOR riskdutyfa0_ where (riskdutyfa0_.SIGN='1' )
13:25:05,667 INFO  [STDOUT] false
13:25:05,698 INFO  [PropertyMessageResources] Initializing, config='org.apache.struts.taglib.logic.LocalStrings', returnNull=true
13:25:05,714 INFO  [PropertyMessageResources] Initializing, config='org.apache.struts.taglib.html.LocalStrings', returnNull=true
13:27:47,029 INFO  [STDOUT] Hibernate: select count(*) as col_0_0_ from XFLIU.RISKDUTY riskduty0_ where (riskduty0_.DUTYNAME='公共交通意外伤害' )
13:27:47,076 INFO  [STDOUT] Hibernate: select riskdutyfa0_.RISKDUTYFACTORID as RISKDUTY1_0_, riskdutyfa0_.FACTORNAME as FACTORNAME0_0_, riskdutyfa0_.FACTORUNIT as FACTORUNIT0_0_, riskdutyfa0_.VALUE as VALUE0_0_, riskdutyfa0_.SIGN as SIGN0_0_, riskdutyfa0_.LANGUAGE as LANGUAGE0_0_ from XFLIU.RISKDUTYFACTOR riskdutyfa0_ where riskdutyfa0_.RISKDUTYFACTORID=?
13:27:47,123 INFO  [RiskDutyServiceImpl] 保险期间       
13:27:47,123 INFO  [STDOUT] Hibernate: select riskdutyfa0_.RISKDUTYFACTORID as RISKDUTY1_0_, riskdutyfa0_.FACTORNAME as FACTORNAME0_0_, riskdutyfa0_.FACTORUNIT as FACTORUNIT0_0_, riskdutyfa0_.VALUE as VALUE0_0_, riskdutyfa0_.SIGN as SIGN0_0_, riskdutyfa0_.LANGUAGE as LANGUAGE0_0_ from XFLIU.RISKDUTYFACTOR riskdutyfa0_ where riskdutyfa0_.RISKDUTYFACTORID=?
13:27:47,138 INFO  [RiskDutyServiceImpl] 计算方向       
13:27:47,138 INFO  [STDOUT] Hibernate: select riskdutyfa0_.RISKDUTYFACTORID as RISKDUTY1_0_, riskdutyfa0_.FACTORNAME as FACTORNAME0_0_, riskdutyfa0_.FACTORUNIT as FACTORUNIT0_0_, riskdutyfa0_.VALUE as VALUE0_0_, riskdutyfa0_.SIGN as SIGN0_0_, riskdutyfa0_.LANGUAGE as LANGUAGE0_0_ from XFLIU.RISKDUTYFACTOR riskdutyfa0_ where riskdutyfa0_.RISKDUTYFACTORID=?
13:27:47,154 INFO  [RiskDutyServiceImpl] 费率             
13:27:47,154 INFO  [RiskDutyServiceImpl] begin save complexCheck riskDuty
13:27:47,154 INFO  [STDOUT] Hibernate: values nextval for S_RISKDUTY
13:27:47,154 INFO  [RiskDutyDAOImpl] save successful
13:27:47,170 INFO  [STDOUT] Hibernate: insert into XFLIU.RISKDUTY (DUTYNAME, DUTYTYPE, LANGUAGE, RISKDUTYID) values (?, ?, ?, ?)
13:27:47,185 INFO  [STDOUT] Hibernate: insert into FACTORRISKDUTY (RISKDUTYID, RISKDUTYFACTORID) values (?, ?)
13:27:47,997 INFO  [STDOUT] Hibernate: insert into FACTORRISKDUTY (RISKDUTYID, RISKDUTYFACTORID) values (?, ?)
13:27:47,997 INFO  [STDOUT] Hibernate: insert into FACTORRISKDUTY (RISKDUTYID, RISKDUTYFACTORID) values (?, ?)
13:27:48,028 INFO  [STDOUT] Hibernate: select riskdutyfa0_.RISKDUTYFACTORID as RISKDUTY1_, riskdutyfa0_.FACTORNAME as FACTORNAME0_, riskdutyfa0_.FACTORUNIT as FACTORUNIT0_, riskdutyfa0_.VALUE as VALUE0_, riskdutyfa0_.SIGN as SIGN0_, riskdutyfa0_.LANGUAGE as LANGUAGE0_ from XFLIU.RISKDUTYFACTOR riskdutyfa0_ where (riskdutyfa0_.SIGN='0' )
13:27:48,044 INFO  [STDOUT] Hibernate: select riskdutyfa0_.RISKDUTYFACTORID as RISKDUTY1_, riskdutyfa0_.FACTORNAME as FACTORNAME0_, riskdutyfa0_.FACTORUNIT as FACTORUNIT0_, riskdutyfa0_.VALUE as VALUE0_, riskdutyfa0_.SIGN as SIGN0_, riskdutyfa0_.LANGUAGE as LANGUAGE0_ from XFLIU.RISKDUTYFACTOR riskdutyfa0_ where (riskdutyfa0_.SIGN='0' )
13:27:48,044 INFO  [STDOUT] false
13:27:48,075 INFO  [STDOUT] Hibernate: select riskdutyfa0_.RISKDUTYFACTORID as RISKDUTY1_, riskdutyfa0_.FACTORNAME as FACTORNAME0_, riskdutyfa0_.FACTORUNIT as FACTORUNIT0_, riskdutyfa0_.VALUE as VALUE0_, riskdutyfa0_.SIGN as SIGN0_, riskdutyfa0_.LANGUAGE as LANGUAGE0_ from XFLIU.RISKDUTYFACTOR riskdutyfa0_ where (riskdutyfa0_.SIGN='1' )
13:27:48,075 INFO  [STDOUT] Hibernate: select riskdutyfa0_.RISKDUTYFACTORID as RISKDUTY1_, riskdutyfa0_.FACTORNAME as FACTORNAME0_, riskdutyfa0_.FACTORUNIT as FACTORUNIT0_, riskdutyfa0_.VALUE as VALUE0_, riskdutyfa0_.SIGN as SIGN0_, riskdutyfa0_.LANGUAGE as LANGUAGE0_ from XFLIU.RISKDUTYFACTOR riskdutyfa0_ where (riskdutyfa0_.SIGN='1' )
13:27:48,091 INFO  [STDOUT] false
13:28:11,263 INFO  [STDOUT] Hibernate: select count(*) as col_0_0_ from XFLIU.RISKDUTY riskduty0_ where (riskduty0_.DUTYNAME='意外死亡' )
13:28:11,279 INFO  [STDOUT] Hibernate: select riskdutyfa0_.RISKDUTYFACTORID as RISKDUTY1_0_, riskdutyfa0_.FACTORNAME as FACTORNAME0_0_, riskdutyfa0_.FACTORUNIT as FACTORUNIT0_0_, riskdutyfa0_.VALUE as VALUE0_0_, riskdutyfa0_.SIGN as SIGN0_0_, riskdutyfa0_.LANGUAGE as LANGUAGE0_0_ from XFLIU.RISKDUTYFACTOR riskdutyfa0_ where riskdutyfa0_.RISKDUTYFACTORID=?
13:28:11,279 INFO  [RiskDutyServiceImpl] 保险期间       
13:28:11,279 INFO  [STDOUT] Hibernate: select riskdutyfa0_.RISKDUTYFACTORID as RISKDUTY1_0_, riskdutyfa0_.FACTORNAME as FACTORNAME0_0_, riskdutyfa0_.FACTORUNIT as FACTORUNIT0_0_, riskdutyfa0_.VALUE as VALUE0_0_, riskdutyfa0_.SIGN as SIGN0_0_, riskdutyfa0_.LANGUAGE as LANGUAGE0_0_ from XFLIU.RISKDUTYFACTOR riskdutyfa0_ where riskdutyfa0_.RISKDUTYFACTORID=?
13:28:11,294 INFO  [RiskDutyServiceImpl] 计算方向       
13:28:11,294 INFO  [STDOUT] Hibernate: select riskdutyfa0_.RISKDUTYFACTORID as RISKDUTY1_0_, riskdutyfa0_.FACTORNAME as FACTORNAME0_0_, riskdutyfa0_.FACTORUNIT as FACTORUNIT0_0_, riskdutyfa0_.VALUE as VALUE0_0_, riskdutyfa0_.SIGN as SIGN0_0_, riskdutyfa0_.LANGUAGE as LANGUAGE0_0_ from XFLIU.RISKDUTYFACTOR riskdutyfa0_ where riskdutyfa0_.RISKDUTYFACTORID=?
13:28:11,294 INFO  [RiskDutyServiceImpl] 费率             
13:28:11,294 INFO  [RiskDutyServiceImpl] begin save complexCheck riskDuty
13:28:11,294 INFO  [STDOUT] Hibernate: values nextval for S_RISKDUTY
13:28:11,310 ERROR [RiskDutyDAOImpl] save failed
org.springframework.orm.hibernate3.HibernateSystemException: a different object with the same identifier value was already associated with the session: [com.sleb.po.Riskdutyfactor#5]; nested exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.sleb.po.Riskdutyfactor#5]
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.sleb.po.Riskdutyfactor#5]
at org.hibernate.engine.PersistenceContext.checkUniqueness(PersistenceContext.java:586)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performUpdate(DefaultSaveOrUpdateEventListener.java:254)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsDetached(DefaultSaveOrUpdateEventListener.java:214)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:91)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:468)
at org.hibernate.engine.Cascades$5.cascade(Cascades.java:154)
at org.hibernate.engine.Cascades.cascadeAssociation(Cascades.java:771)
at org.hibernate.engine.Cascades.cascade(Cascades.java:720)
at org.hibernate.engine.Cascades.cascadeCollection(Cascades.java:895)
at org.hibernate.engine.Cascades.cascadeAssociation(Cascades.java:792)
at org.hibernate.engine.Cascades.cascade(Cascades.java:720)
at org.hibernate.engine.Cascades.cascade(Cascades.java:847)
at org.hibernate.event.def.AbstractSaveEventListener.cascadeAfterSave(AbstractSaveEventListener.java:363)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:265)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:160)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:108)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:173)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:481)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:476)
at org.springframework.orm.hibernate3.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:615)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:365)
at org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:612)
at com.sleb.dao.base.BaseDao.save(BaseDao.java:100)
at com.sleb.service.riskDuty.spring.RiskDutyServiceImpl.saveRiskduty(RiskDutyServiceImpl.java:56)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:335)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:181)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
at $Proxy47.saveRiskduty(Unknown Source)
at com.sleb.struts.action.riskDuty.SaveRiskDutyAction.save(SaveRiskDutyAction.java:92)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:216)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at com.sleb.util.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:74)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:174)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:75)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:44)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:169)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)
13:28:11,388 WARN  [RequestProcessor] Unhandled Exception thrown: class org.springframework.orm.hibernate3.HibernateSystemException
13:28:11,435 ERROR [Engine] StandardWrapperValve[action]: Servlet.service() for servlet action threw exception
org.springframework.orm.hibernate3.HibernateSystemException: a different object with the same identifier value was already associated with the session: [com.sleb.po.Riskdutyfactor#5]; nested exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.sleb.po.Riskdutyfactor#5]
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.sleb.po.Riskdutyfactor#5]
at org.hibernate.engine.PersistenceContext.checkUniqueness(PersistenceContext.java:586)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performUpdate(DefaultSaveOrUpdateEventListener.java:254)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsDetached(DefaultSaveOrUpdateEventListener.java:214)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:91)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:468)
at org.hibernate.engine.Cascades$5.cascade(Cascades.java:154)
at org.hibernate.engine.Cascades.cascadeAssociation(Cascades.java:771)
at org.hibernate.engine.Cascades.cascade(Cascades.java:720)
at org.hibernate.engine.Cascades.cascadeCollection(Cascades.java:895)
at org.hibernate.engine.Cascades.cascadeAssociation(Cascades.java:792)
at org.hibernate.engine.Cascades.cascade(Cascades.java:720)
at org.hibernate.engine.Cascades.cascade(Cascades.java:847)
at org.hibernate.event.def.AbstractSaveEventListener.cascadeAfterSave(AbstractSaveEventListener.java:363)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:265)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:160)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:108)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:173)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:481)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:476)
at org.springframework.orm.hibernate3.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:615)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:365)
at org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:612)
at com.sleb.dao.base.BaseDao.save(BaseDao.java:100)
at com.sleb.service.riskDuty.spring.RiskDutyServiceImpl.saveRiskduty(RiskDutyServiceImpl.java:56)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:335)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:181)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
at $Proxy47.saveRiskduty(Unknown Source)
at com.sleb.struts.action.riskDuty.SaveRiskDutyAction.save(SaveRiskDutyAction.java:92)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:216)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at com.sleb.util.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:74)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:174)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:75)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:44)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:169)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)
17 楼 janh 2007-02-17  
可能在
引用
首先查询id为5的User对象 .
Userinfo user = (Userinfo)this.getObject(Userinfo.class, new Long(5))

时是一个session,而在
引用
再执行一个查询
String sql = "select user from User user";
List list = this.getByHqlList(sql);

最后:
user.set***();
this.update();

时是另一个session,可以调试看看是不是同一个session。
16 楼 collin000 2007-02-16  
举个例子:

首先查询id为5的User对象 .
Userinfo user = (Userinfo)this.getObject(Userinfo.class, new Long(5))


再执行一个查询
String sql = "select user from User user";
List list = this.getByHqlList(sql);

最后:
user.set***();
this.update(); 

//居然有问题??? 我改成先session.clear()再update,通过!!
//以上是我简化了实际业务的情况,遇到和楼主同样的错!
//难道这样写法不行??? 望指教!!!

15 楼 collin000 2007-02-16  
楼主的问题我也遇到过了,把session先clear一下就好了,Allen的方法正解!

楼上说:“一个session中如果关联了或者说缓存了一个对象,当你将另一个相同id的游离对象与该session关联起来时会报那个错误。”

这里有个疑问:为什么会出现“一个相同id的游离对象”。如果取这条数据的持久化对象,不论从session取还是查数据库只有一个,怎么就会出现“一个相同id的游离对象”?
14 楼 janh 2007-02-10  
一个session中如果关联了或者说缓存了一个对象,当get或load该id时,只要该对象没有被evict并且该session没有被clear或close过,那么总是会从缓存中直接取,否则查询数据库。session之间是相互独立的,一个session不会去取另一个session缓存中的对象,另一个session缓存中的对象对它来说是游离对象。

一个session中如果关联了或者说缓存了一个对象,当你将另一个相同id的游离对象与该session关联起来时会报那个错误。
13 楼 liutjedu 2007-02-10  
应该是这个的错的,在执行第一次save()方法的时候,通过getRiskDutyFactorByPk(new Integer(baseChecked[i])));方法取得一个RiskDutyFactor对象,但是session没有及时关闭,等执行第2次的时候,同样取得的是一个RiskDutyFactor对象,虽然说ID是一样的,但是对象已经不一样,才可以报这样的错误。

我现在手头上没有代码了,等回来后,把代码打包,发上来,希望大家能批评一下。
12 楼 janh 2007-02-10  
在getRiskDutyFactorByPk(new Integer(baseChecked[i])));时不应该出现这个错误吧,代码贴了很多,为什么不把出错信息贴全呢
11 楼 liutjedu 2007-02-10  
hi,allen:
对于第一种方法,我忘记试过没有,不过我会尝试下的,但是我试过将清空Session放在save()后做过,结果是没有对数据库进行操作。
也在riskDuty.setDutyname(dutyName);前加过,没有什么效果,执行了,但是还是报同样的错。
merge()也尝试了,不过好象还不太会用。我DAO里的save()是save()方法,不是saveOrUpdate().

可能我那里还是有问题的,春节过后,我把代码整理下,发给你,你帮忙给我看看吧,现在我没有代码,放在公司了,我已经请假回家了!

谢谢!顺便祝看我帖子的人新年快乐!
10 楼 Allen 2007-02-09  
我又想了一下——Set本身的特性决定了里面不存在重复的元素……既然这里你能add()进去,那就是说Set集合是OK的。

先用你注释掉的那行代码在save()动作之前清空Session看看行不行:
....

this.getRiskDutyFactorDAO().getCurrentSession().clear(); 
this.getRiskDutyDAO().save(riskDuty);

....

又或者尝试一下以merge()方法来完成持久化(这样应该就不会因为cascade="save-update"而触动到关联的集合端):
....

//也许可以直接写:this.getRiskDutyFactorDAO().merge(riskDuty); 
this.getRiskDutyFactorDAO().getCurrentSession().merge(riskDuty); 

....

另外问一下,你的DAO里面的save()用的是Session的saveOrUpdate()方法吗?
9 楼 liutjedu 2007-02-09  
to Allen    :
我是多对多的,但是riskdutyfactor表已经有数据了,后再对riskduty进行操作,如果都修改为inverse="true",那没有对象来维护中间表了.
不知道我说的对不对.

你说的代码可读性不好,是因为我注释少,还是我说的不清楚呢?希望能说的直白点,呵呵,学习ING.

对于出错的问题,我知道是这两个String[] baseChecked, String[] complexChecked造成的,但是怎么修改呢?
8 楼 Allen 2007-02-09  
很可能的一点是,你的这两个数组里面存在重复相同的值:String[] baseChecked, String[] complexChecked。这进而导致你的DAO层试图将同样Class类型并且含有同样标识符(identifier)的Riskdutyfactor对象关联到它的Session中去,就直接引发了NonUniqueObjectException。

另外,根据你的这段代码所体现的逻辑关系,建议将这个Set集合也设置inverse="true"。
        <set name="riskdutyfactors" table="FACTORRISKDUTY" cascade="save-update">   
            <key>   
                <column name="RISKDUTYID" />   
            </key>   
            <many-to-many class="com.sleb.po.Riskdutyfactor" column="RISKDUTYFACTORID" />   
        </set>
7 楼 Allen 2007-02-09  
这个代码的可阅读性需要加强啊!

我觉得你这里出现问题的原因并不在于是否采用merge()方法来持久化PO……

况且你对merge()的用法也是不对的,它的正确用法请参考API文档。

Session.merge() API doc:
http://www.hibernate.org/hib_docs/v3/api/org/hibernate/Session.html#merge(java.lang.Object)
6 楼 liutjedu 2007-02-09  
	public boolean saveRiskduty(String dutyName, String dutyType,
			String[] baseChecked, String[] complexChecked) {		
		riskDuty.setDutyname(dutyName);
		riskDuty.setDutytype(dutyType);
		
		if (baseChecked != null) {
			for (int i = 0; i < baseChecked.length; i++) {
				log.info(this.getRiskDutyFactorByPk(new Integer(baseChecked[i])).getFactorname());
				//首先根据页面上请求的ID,取得RiskDutyFactor对象,后与RiskDuty关联
				this.getRiskDutyFactorDAO().getCurrentSession().merge(this.getRiskDutyFactorByPk(new Integer(baseChecked[i])));
				riskDuty.getRiskdutyfactors().add(this.getRiskDutyFactorByPk(new Integer(baseChecked[i])));				
			}
		}
		if (complexChecked != null) {
			for (int i = 0; i < complexChecked.length; i++) {
				log.info(this.getRiskDutyFactorByPk(new Integer(complexChecked[i])).getFactorname());
				//首先根据页面上请求的ID,取得RiskDutyFactor对象,后与RiskDuty关联
				this.getRiskDutyFactorDAO().getCurrentSession().merge(this.getRiskDutyFactorByPk(new Integer(complexChecked[i])));
				riskDuty.getRiskdutyfactors().add(this.getRiskDutyFactorByPk(new Integer(complexChecked[i])));
			}
		}
		log.info("begin save complexCheck riskDuty");
		this.getRiskDutyDAO().save(riskDuty);

		bl=true;
		//this.getRiskDutyFactorDAO().getCurrentSession().clear();
		
		return bl;
	}


程序增加了两行,但是还是不对,不知道merge怎么用.
5 楼 liutjedu 2007-02-09  
if (baseChecked != null) {    
  for (int i = 0; i < baseChecked.length; i++) {    
   log.info(this.getRiskDutyFactorByPk(new Integer(baseChecked[i])).getFactorname());    
   //首先根据页面上请求的ID,取得RiskDutyFactor对象,后与RiskDuty关联    
   riskDuty.getRiskdutyfactors().add(this.getRiskDutyFactorByPk(new Integer(baseChecked[i])));        
  }    
 }    

我在网络上搜到过,但是能不能帮我详细的看下我的代码,应该将你说的meger()方法放在那里?谢谢!
4 楼 Allen 2007-02-09  
关于 NonUniqueObjectException ,请看:

http://www.hibernate.org/116.html#A8

这个异常估计是每一个Hibernate使用者都曾经遇到过的……

这样的帖子建议放到新手区。
3 楼 liutjedu 2007-02-09  
谢谢springArt.
2 楼 SpringArt 2007-02-09  
liutjedu 写道
da大家能看到吗?我怎么看不到啊!奇怪!


发表代码请用code包含。BBCODE模式下,用Code包含, RichEdit模式下用代码输入窗口输入代码。

相关推荐

    老生常谈Session和Cookie之间区别与联系(必看篇)

    在实际开发中,对Session和Cookie的管理需要特别注意安全性问题。例如,需要在服务器端对Session进行定期更新和失效机制,防止Session劫持;同时对Cookie的传输使用加密、设置HttpOnly属性等手段防止跨站脚本攻击...

    老生常谈外链 站长要做到对症下药.pps

    老生常谈外链 站长要做到对症下药.pps

    Java中文问题及最优解决方法

    由于Java编程中的中文问题是一个老生常谈的问题,在阅读了许多关于Java中文问题解决方法之后,结合作者的编程实践,我发现过去谈的许多方法都不能清晰地说明问题及解决问题,尤其是跨平台时的中文问题。于是我给出此...

    老生常谈的24种Java设计模式

    Java设计模式是在特定环境下,为了解决某类重复出现的问题而总结出来的一套成功或有效的解决方案。这些设计模式旨在提高代码的可重用性、可维护性和可扩展性。 设计模式通常包含以下几个关键要素: 模式名称:通过一...

    电子技术的老生常谈——接地.pdf

    正如标题所言,《电子技术的老生常谈——接地》一文中提到的那样,尽管接地的基本概念在每一次培训和交流中都会被提及,但往往缺乏一个通用而全面的方法论指导。本文旨在深入探讨接地的各种类型、目的以及具体的实施...

    老生常谈javascript的面向对象思想

    第二种方式是通过共享同一个函数来避免重复定义函数,这虽然解决了内存使用的问题,但是从语义上讲,函数与对象的关联度不高,可能导致代码的可读性降低。 第四种是构造函数方式。这种方式中,构造函数可以认为是一...

    老生常谈ProgressBar、ProgessDialog的用法

    ProgressBar和ProgressDialog是Android开发中常见的两种进度条控件,用于展示任务执行的进度或等待状态。下面我们将深入探讨这两种控件的用法。 首先,ProgressBar是一个可以显示具体进度的组件,它可以是圆形或...

    老生常谈遮罩层 滚动条的问题

    今天遇到的问题是,在弹出层后面的 遮罩层,因为有滚动条,导致滚动条下面不可视区域没有遮罩层,解决方式是加的css。 js代码 [removed] //显示灰色JS遮罩层 function showBg(ct,content){ var bH=$(document)....

    解决 U-Boot ping不通虚拟机的问题

    老生常谈 虚拟机的网络配置 设置桥接模式 接下来打开虚拟网络编辑器 注意手动选择你电脑的有线网卡 解决虚拟机无法上网的问题 上面几步完成后可能会出现虚拟机连不上网的情况 3. 设置共享网络 既然用网线连接PC...

    老生常谈android中的事件传递和处理机制

    在Android开发中,事件传递和处理机制是相当关键的一个部分,尤其对于用户界面的交互有着决定性的影响。本文主要探讨了Android系统如何处理触摸事件,通过拟人化的比喻来解释事件传递的流程,并通过实际代码示例进行...

    Java中文乱码解决之道

    java编码中的中文问题是一个老生常谈的问题了,每次遇到中文乱码LZ要么是按照以前的经验修改,要么则是baidu.com来解决问题。阅读许多关于中文乱码的解决办法的博文后,发现对于该问题我们都(更加包括我自己)没有...

    js老生常谈之this,constructor ,prototype全面解析

    javascript中的this,constructor ,prototype,都是老生常谈的问题,深入理解他们的含义至关重要。在这里,我们再来复习一下吧,温故而知新! this this表示当前对象,如果在全局作用范围内使用this,则指代当前页面...

    老生常谈C++中实参形参的传递问题

    "C++中实参形参的传递问题" 在 C++ 中,函数参数的传递是非常重要的概念。函数参数的传递方式对函数的执行结果和性能都有着重要的影响。今天,我们就来探讨 C++ 中实参形参的传递问题。 首先,让我们来了解什么是...

    老生常谈计算机中的编码问题(必看篇)

    计算机中的编码问题是一个至关重要的概念,它涉及到计算机如何理解和处理文本信息。计算机本质上只能处理数字,因此,要处理文本,就必须将文本转换成数字形式。本文主要探讨了几种常见的编码方式,包括ASCII编码、...

    浅探中国电子商务发展中的问题与对策-1.docx

    安全问题是电子商务中的老生常谈,但老生常谈常常说明非常重要且解决得不够理想。可以说目前阻碍个人或企业进行网上交易的最大的心理障碍,就是电子交易平台及网络的安全问题。 2. 物流水平落后 电子商务的优势...

    老生常谈JavaScript面向对象基础与this指向问题

    本文将深入探讨面向对象的基础概念,包括面向过程与面向对象的区别,以及JavaScript中特有的this指向问题。 首先,我们要理解面向过程和面向对象的区别。面向过程编程是一种自下而上的编程范式,关注解决问题的具体...

    老生常谈python中的重载

    所谓重载,就是多个相同函数名的函数,根据传入的参数个数,参数类型而执行不同的功能。所以函数重载实质上是为了解决编程中参数可变不统一的问题。这篇文章主要介绍了老生常谈python中的重载,需要的朋友可以参考下

Global site tag (gtag.js) - Google Analytics