- 浏览: 46664 次
- 性别:
- 来自: 天津
最新评论
-
ddandyy:
还真把做软件的想成怎么样了
不就是给人擦擦的么
让你做什么就做 ...
面对这样的供应商,真的无话可说了。 -
xiaoyu:
不是一个组, 是一个客户, 一个供应商(对上了. 哈)
面对这样的供应商,真的无话可说了。 -
抛出异常的爱:
可能上个说身份证重的与楼主是在一个项目组中?
面对这样的供应商,真的无话可说了。 -
weiqingfei:
现有阶段,身份证是可以重复的,否则你的系统有可能跑不起来。
面对这样的供应商,真的无话可说了。 -
coder_hero:
身份证确实是可以重复的
面对这样的供应商,真的无话可说了。
目前的结构采用的是Struts+spring+hibernate,目前遇到一个问题,Riskdutyfactor表与riskDuty是多对多的关系,中间表为factorRiskDuty
配置文件如下:
RISKDUTY表:
- <hibernate-mapping>
- <class name="com.sleb.po.Riskduty" table="RISKDUTY" schema="XFLIU">
- <id name="riskdutyid" type="integer">
- <column name="RISKDUTYID" />
- <generator class="sequence" >
- <param name="sequence">S_RISKDUTY</param>
- </generator>
- </id>
- .....
- <set name="riskdutyrisks" inverse="true">
- <key>
- <column name="RISKDUTYID" />
- </key>
- <one-to-many class="com.sleb.po.Riskdutyrisk" />
- </set>
- <!-- 设计责任和责任要素的多对多的关联,手动修改过,中间表名称为FACTORRISKDUTY-->
- <set name="riskdutyfactors" table="FACTORRISKDUTY" cascade="save-update">
- <key>
- <column name="RISKDUTYID" />
- </key>
- <many-to-many class="com.sleb.po.Riskdutyfactor" column="RISKDUTYFACTORID" />
- </set>
- </class>
- </hibernate-mapping>
------------------------
riskdutyfactor表映射文件: ----------先对以上进行解释,有一个界面是用来增加RISKDUTYFACTOR表中的数据的,另一个界面用来增加RISKDUTY数据的,在增加RISKDUTY的时候,需要使用RISKDUTYFACTOR表中的数据,由于是多对多的关系,因此增加FACTORRISKDUTY中间表.由以上可以知道riskduty增加的时候,再对中间表进行更新,因此设置RISKDUTY配置文件中的cascade="save-update"> 来维护关系,我想这个是正确的,因为我能正确的增加数据.RiskDutyService程序如下:
- // 保存一个责任要素
- 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关联
- 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关联
- 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;
- }
第一次增加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 中的配置文件修改为:
<!---->
请教高手!
<bean id="riskDutyService" parent="proxyTemplate"></bean>
- <!--riskDuty service -->
- <bean id="riskDutyService" parent="proxyTemplate">
- <property name="target">
- <bean class="com.sleb.service.riskDuty.spring.RiskDutyServiceImpl">
- <property name="riskDutyDAO">
- <ref local="riskDutyDAO" />
- </property>
- <property name="riskDutyFactorDAO">
- <ref local="riskDutyFactorDAO" />
- </property>
- </bean>
- </property>
- </bean>
- <bean id="riskDutyDAO" class="com.sleb.dao.riskDuty.RiskDutyDAOImpl">
- <property name="sessionFactory">
- <ref bean="sessionFactory" />
- </property>
- </bean>
- <hibernate-mapping>
- <class name="com.sleb.po.Riskdutyfactor" table="RISKDUTYFACTOR" schema="XFLIU">
- <id name="riskdutyfactorid" type="integer">
- <column name="RISKDUTYFACTORID" />
- <generator class="sequence" >
- <param name="sequence">S_RISKDUTYFACTOR</param>
- </generator>
- </id>
- <property name="factorname" type="string">
- <column name="FACTORNAME" length="20" />
- </property>
- <property name="factorunit" type="string">
- <column name="FACTORUNIT" length="120" />
- </property>
- <property name="value" type="string">
- <column name="VALUE" length="120" />
- </property>
- <property name="sign" type="string">
- <column name="SIGN" length="1" />
- </property>
- <property name="language" type="string">
- <column name="LANGUAGE" length="1" />
- </property>
- <!-- 设计责任要素和责任的多对多的关联,手动修改过,中间表名称为FACTORRISKDUTY-->
- <set name="riskduties" table="FACTORRISKDUTY" inverse="true" cascade="none">
- <key>
- <column name="RISKDUTYFACTORID" />
- </key>
- <many-to-many class="com.sleb.po.Riskduty" column="RISKDUTYID" />
- </set>
- </class>
- </hibernate-mapping>
<hibernate-mapping></hibernate-mapping>
评论
我在第一次操作的时候,可以增加的,但是等第2次操作的时候,就报以上错误.也就是不可能是你提到的一次处理过程中出现了多个session.
哪位大哥,可以给帮忙调试下,已经好久了,都弄不明白.谢谢!
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)
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。
首先查询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,通过!!
//以上是我简化了实际业务的情况,遇到和楼主同样的错!
//难道这样写法不行??? 望指教!!!
楼上说:“一个session中如果关联了或者说缓存了一个对象,当你将另一个相同id的游离对象与该session关联起来时会报那个错误。”
这里有个疑问:为什么会出现“一个相同id的游离对象”。如果取这条数据的持久化对象,不论从session取还是查数据库只有一个,怎么就会出现“一个相同id的游离对象”?
一个session中如果关联了或者说缓存了一个对象,当你将另一个相同id的游离对象与该session关联起来时会报那个错误。
我现在手头上没有代码了,等回来后,把代码打包,发上来,希望大家能批评一下。
对于第一种方法,我忘记试过没有,不过我会尝试下的,但是我试过将清空Session放在save()后做过,结果是没有对数据库进行操作。
也在riskDuty.setDutyname(dutyName);前加过,没有什么效果,执行了,但是还是报同样的错。
merge()也尝试了,不过好象还不太会用。我DAO里的save()是save()方法,不是saveOrUpdate().
可能我那里还是有问题的,春节过后,我把代码整理下,发给你,你帮忙给我看看吧,现在我没有代码,放在公司了,我已经请假回家了!
谢谢!顺便祝看我帖子的人新年快乐!
先用你注释掉的那行代码在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()方法吗?
我是多对多的,但是riskdutyfactor表已经有数据了,后再对riskduty进行操作,如果都修改为inverse="true",那没有对象来维护中间表了.
不知道我说的对不对.
你说的代码可读性不好,是因为我注释少,还是我说的不清楚呢?希望能说的直白点,呵呵,学习ING.
对于出错的问题,我知道是这两个String[] baseChecked, String[] complexChecked造成的,但是怎么修改呢?
另外,根据你的这段代码所体现的逻辑关系,建议将这个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>
我觉得你这里出现问题的原因并不在于是否采用merge()方法来持久化PO……
况且你对merge()的用法也是不对的,它的正确用法请参考API文档。
Session.merge() API doc:
http://www.hibernate.org/hib_docs/v3/api/org/hibernate/Session.html#merge(java.lang.Object)
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怎么用.
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()方法放在那里?谢谢!
http://www.hibernate.org/116.html#A8
这个异常估计是每一个Hibernate使用者都曾经遇到过的……
这样的帖子建议放到新手区。
发表代码请用code包含。BBCODE模式下,用Code包含, RichEdit模式下用代码输入窗口输入代码。
相关推荐
在实际开发中,对Session和Cookie的管理需要特别注意安全性问题。例如,需要在服务器端对Session进行定期更新和失效机制,防止Session劫持;同时对Cookie的传输使用加密、设置HttpOnly属性等手段防止跨站脚本攻击...
老生常谈外链 站长要做到对症下药.pps
由于Java编程中的中文问题是一个老生常谈的问题,在阅读了许多关于Java中文问题解决方法之后,结合作者的编程实践,我发现过去谈的许多方法都不能清晰地说明问题及解决问题,尤其是跨平台时的中文问题。于是我给出此...
Java设计模式是在特定环境下,为了解决某类重复出现的问题而总结出来的一套成功或有效的解决方案。这些设计模式旨在提高代码的可重用性、可维护性和可扩展性。 设计模式通常包含以下几个关键要素: 模式名称:通过一...
正如标题所言,《电子技术的老生常谈——接地》一文中提到的那样,尽管接地的基本概念在每一次培训和交流中都会被提及,但往往缺乏一个通用而全面的方法论指导。本文旨在深入探讨接地的各种类型、目的以及具体的实施...
第二种方式是通过共享同一个函数来避免重复定义函数,这虽然解决了内存使用的问题,但是从语义上讲,函数与对象的关联度不高,可能导致代码的可读性降低。 第四种是构造函数方式。这种方式中,构造函数可以认为是一...
ProgressBar和ProgressDialog是Android开发中常见的两种进度条控件,用于展示任务执行的进度或等待状态。下面我们将深入探讨这两种控件的用法。 首先,ProgressBar是一个可以显示具体进度的组件,它可以是圆形或...
今天遇到的问题是,在弹出层后面的 遮罩层,因为有滚动条,导致滚动条下面不可视区域没有遮罩层,解决方式是加的css。 js代码 [removed] //显示灰色JS遮罩层 function showBg(ct,content){ var bH=$(document)....
老生常谈 虚拟机的网络配置 设置桥接模式 接下来打开虚拟网络编辑器 注意手动选择你电脑的有线网卡 解决虚拟机无法上网的问题 上面几步完成后可能会出现虚拟机连不上网的情况 3. 设置共享网络 既然用网线连接PC...
在Android开发中,事件传递和处理机制是相当关键的一个部分,尤其对于用户界面的交互有着决定性的影响。本文主要探讨了Android系统如何处理触摸事件,通过拟人化的比喻来解释事件传递的流程,并通过实际代码示例进行...
java编码中的中文问题是一个老生常谈的问题了,每次遇到中文乱码LZ要么是按照以前的经验修改,要么则是baidu.com来解决问题。阅读许多关于中文乱码的解决办法的博文后,发现对于该问题我们都(更加包括我自己)没有...
javascript中的this,constructor ,prototype,都是老生常谈的问题,深入理解他们的含义至关重要。在这里,我们再来复习一下吧,温故而知新! this this表示当前对象,如果在全局作用范围内使用this,则指代当前页面...
"C++中实参形参的传递问题" 在 C++ 中,函数参数的传递是非常重要的概念。函数参数的传递方式对函数的执行结果和性能都有着重要的影响。今天,我们就来探讨 C++ 中实参形参的传递问题。 首先,让我们来了解什么是...
计算机中的编码问题是一个至关重要的概念,它涉及到计算机如何理解和处理文本信息。计算机本质上只能处理数字,因此,要处理文本,就必须将文本转换成数字形式。本文主要探讨了几种常见的编码方式,包括ASCII编码、...
安全问题是电子商务中的老生常谈,但老生常谈常常说明非常重要且解决得不够理想。可以说目前阻碍个人或企业进行网上交易的最大的心理障碍,就是电子交易平台及网络的安全问题。 2. 物流水平落后 电子商务的优势...
本文将深入探讨面向对象的基础概念,包括面向过程与面向对象的区别,以及JavaScript中特有的this指向问题。 首先,我们要理解面向过程和面向对象的区别。面向过程编程是一种自下而上的编程范式,关注解决问题的具体...
所谓重载,就是多个相同函数名的函数,根据传入的参数个数,参数类型而执行不同的功能。所以函数重载实质上是为了解决编程中参数可变不统一的问题。这篇文章主要介绍了老生常谈python中的重载,需要的朋友可以参考下