- 浏览: 47134 次
- 性别:
- 来自: 天津
-
最新评论
-
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属性等手段防止跨站脚本攻击...
在使用注册表模式时需要注意控制数据访问的权限,避免不恰当的使用导致数据安全问题。此外,由于全局变量的特性,在设计系统架构时应合理规划数据的作用域,以避免维护上的混乱。 通过本文的介绍,我们对PHP面向...
邮件发送是一个老生常谈的问题了,代码虽然简单,但是许多小伙伴对过程不太理解,这篇文章将对邮件发送过程中的各种协议和技术细节进行详细的讲解。 邮件协议 邮件协议我们经常会听到各种各样的邮件协议,比如 SMTP...
内容概要:本文详细介绍了应用于电镀生产线的西门子S7-300 PLC控制系统的程序设计、硬件配置以及调试过程中积累的实际经验。主要内容涵盖温度控制、条码记录、行车定位、故障排查等方面的技术细节。文中展示了多个关键功能模块的具体实现方法,如PID温度控制、条码数据处理、行车定位判断等,并分享了一些实用的调试技巧和注意事项。此外,还讨论了硬件配置中的重要细节,如模块地址分配、网络拓扑设计等。 适合人群:从事自动化控制领域的工程师和技术人员,尤其是对PLC编程有一定基础的人群。 使用场景及目标:适用于需要深入了解和掌握电镀生产线自动化控制技术的专业人士。目标是帮助读者理解S7-300 PLC在电镀生产线中的具体应用,提高实际项目的开发效率和可靠性。 其他说明:文章不仅提供了详细的程序代码示例,还分享了许多来自一线的真实案例和实践经验,对于解决实际工程中的问题具有很高的参考价值。
内容概要:本文详细介绍了使用COMSOL Multiphysics进行固体超声导波的二维仿真过程。作者通过建立一个10mm×100mm的铝板模型,应用汉宁窗调制的5周期200kHz正弦激励信号,研究了超声导波在铝板中的传播特性及其模式转换现象。文中涵盖了从模型构建、材料参数设置、网格划分、边界条件设定、激励信号施加到求解设置以及结果分析的完整流程。特别强调了汉宁窗调制的作用,即减少频谱泄漏并提高信号质量。 适合人群:从事超声检测、材料科学、物理学等相关领域的研究人员和技术人员,尤其是那些希望深入了解COMSOL仿真工具及其在超声导波研究中应用的人群。 使用场景及目标:适用于需要精确模拟超声波在固体介质中传播的研究项目,旨在验证理论预测、优化实验设计、评估不同材料和结构对超声波的影响。此外,还可以用于教学目的,帮助学生掌握COMSOL软件的操作方法和超声导波的基础知识。 其他说明:文中提供了详细的参数设置指导和代码片段,有助于读者快速复现仿真过程。同时,作者分享了一些实用技巧,如如何正确设置网格大小、选择合适的窗函数等,以确保仿真结果的准确性。
离职人员分析仪表盘.xlsx
内容概要:本文详细介绍了如何利用LabVIEW搭建一个多功能的虚拟函数信号发生器及其信号分析功能。首先,文章展示了如何通过LabVIEW的前面板和程序框图创建各种常见波形(如正弦波、方波、三角波等),并深入探讨了波形生成的具体实现方法,包括三角波的周期性和斜率计算、白噪声的生成以及自定义公式的解析。接着,文章讨论了信号处理的关键技术,如自相关分析、频谱分析、积分和微分运算,并提供了具体的实现代码和注意事项。此外,文中还分享了一些实用的经验和技术细节,如避免频谱泄漏的方法、处理多频波的技术、防止内存泄漏的措施等。 适用人群:从事信号处理、电子工程、自动化控制等领域的工作技术人员,尤其是那些熟悉或希望学习LabVIEW编程的人士。 使用场景及目标:适用于实验室环境或教学环境中,用于替代传统物理信号发生器进行信号生成和分析实验。主要目标是提高信号生成和分析的灵活性和便捷性,减少对昂贵硬件设备的依赖。 其他说明:本文不仅提供了详细的代码示例,还分享了许多作者在实践中积累的经验教训,帮助读者更好地理解和应用LabVIEW进行信号处理。
线性代数
大雾至尊版V56泛滥无密码.zip
员工生日关怀方案
试用期情况跟踪表.xls
员工激励机制与技巧
员工晋升的自我评价.doc
基于51单片机protues仿真的多功能婴儿车控制器(仿真图、源代码、AD原理图) 该设计为51单片机protues仿真的多功能婴儿车控制器,实现温湿度,音乐,避障,声音监测控制; 1、温湿度检测,婴儿尿湿时会有提醒。 2、声音检测,当婴儿啼哭时也会有提醒。 3、小车避障,小车遇到障碍会后退左转。 4、音乐播放。 5、仿真图、源代码、AD原理图;
内容概要:本文档详细介绍了计算机求职笔试的内容与解答,涵盖编程语言基础、数据结构与算法、编程实践与调试、系统设计与软件工程以及综合题型与开放题五个方面。编程语言基础部分强调了语法规则、数据类型与运算符、面向对象编程的核心概念;数据结构与算法部分讲解了常见数据结构(如线性结构、树与图、哈希表)和高频算法(如排序算法、动态规划、递归与回溯);编程实践与调试部分关注编码能力和调试技巧;系统设计与软件工程部分探讨了设计模式、模块化设计、数据库与网络知识;综合题型与开放题部分则提供了场景题和逻辑思维题的示例。最后给出了备考建议,包括知识体系构建、刷题策略和模拟实战的方法。 适合人群:即将参加计算机相关职位笔试的求职者,特别是对编程语言、数据结构、算法设计有初步了解的应届毕业生或初级工程师。 使用场景及目标:①帮助求职者系统复习计算机基础知识,提升笔试通过率;②通过例题和解答加深对编程语言、数据结构、算法的理解;③提供模拟实战环境,提高时间管理和抗压能力。 阅读建议:建议按照文档提供的知识体系顺序进行系统复习,重点攻克高频题型,利用在线平台刷题练习,并结合实际项目经验进行综合应用,同时注意时间管理和抗压能力的训练。
SecureCRT安装包
物流业人才流失与紧缺现象的对策研究
招聘渠道费用仪表盘P10.pptx
内容概要:本文详细介绍了五相永磁同步电机在Simulink环境下的PI双闭环SVPWM矢量控制建模过程及其优化方法。首先阐述了五相电机相比三相电机的优势,如更小的转矩脉动和更强的容错能力。接着探讨了复杂的Simulink模型搭建,涉及电机本体模块、坐标变换模块、SVPWM模块和PI调节器模块等多个组件。文中提供了具体的Clark变换和PI调节器的代码示例,解释了双闭环控制的工作原理,并详细描述了SVPWM与十扇区划分的具体实现方式。最后展示了模型的性能表现,包括良好的波形质量和快速的动态响应特性。 适合人群:从事电机控制领域的研究人员和技术人员,尤其是对五相永磁同步电机和Simulink建模感兴趣的读者。 使用场景及目标:适用于希望深入了解五相永磁同步电机控制原理并掌握具体实现方法的研究人员和技术人员。目标是帮助读者理解五相电机的特殊性和复杂性,掌握PI双闭环SVPWM矢量控制的建模技巧,提高电机控制系统的设计水平。 其他说明:文章不仅提供了理论知识,还包括了大量的代码片段和实践经验分享,有助于读者更好地理解和应用相关技术。
员工离职交接表-模板.doc