why not rollback on exception?
Code:
public String execute() throws Exception {
for (int i = 0; i < model.getWspzxh().length; i++) {
Session session = null;
Session xfileSession = null;
try {
session = sourceSessionFactory.openSession();
xfileSession = xfileSessionFactory.openSession();
Query query = session.createQuery("from KydaWsDjxxTmp wsDjxx where (wsDjxx.nsrsbh=:nsrsbh) and (wsDjxx.wspzxh=:wspzxh)");
query.setString("nsrsbh", model.getNsrsbh()[i]);
query.setString("wspzxh", model.getWspzxh()[i]);
Iterator it = query.iterate();
if (it.hasNext()) {
KydaWsDjxxTmp wsDjxx = (KydaWsDjxxTmp)it.next();
StringBuffer uri = new StringBuffer();
uri.append("model.wspzxh=");
uri.append(wsDjxx.getWspzxh());
uri.append("&");
uri.append("model.nsrsbh=");
uri.append(wsDjxx.getNsrsbh());
uri.append("&");
uri.append("model.wszldm=");
uri.append(wsDjxx.getWszlDm());
Xtype xtype = new Xtype();
xtype.setSymbol("WS" + wsDjxx.getWszlDm());
Xource xource = new Xource();
xource.setXtype(xtype);
xource.setUri(uri.toString());
xource.setTitle(wsDjxx.getWszlDm());
xource.setCreateTime(wsDjxx.getSlxhrq());
xource.setXourceOwner(wsDjxx.getNsrsbh());
xource.setXourceGroup(wsDjxx.getSwjgDm());
xource.setCollectTime(new Date());
xfileSession.save(xource);
KydaWsDjxxGd wsDjxx2 = new KydaWsDjxxGd();
BeanUtils.copyProperties(wsDjxx2, wsDjxx);
session.save(wsDjxx2);
// session.delete(wsDjxx);
StringBuffer hql = new StringBuffer();
hql.append(" from KydaFszl fszl where (fszl.wspzxh=:wspzxh) and (fszl.nsrsbh=:nsrsbh) ");
hql.append(" order by fszl.qcfwDmWsfxzl.wsfszlDm, fszl.pageNo ");
Query fszlQuery = session.createQuery(hql.toString());
fszlQuery.setString("nsrsbh", model.getNsrsbh()[i]);
fszlQuery.setString("wspzxh", model.getWspzxh()[i]);
it = fszlQuery.iterate();
while (it.hasNext()) {
KydaFszl row = (KydaFszl)it.next();
Xtype imageXtype = new Xtype();
imageXtype.setSymbol("IMAGE");
Xource image = new Xource();
image.setXtype(imageXtype);
uri = new StringBuffer();
uri.append("fileName=");
uri.append(row.getFileName());
image.setUri(uri.toString());
image.setCreateTime(row.getUploadtime());
image.setTitle(row.getQcfwDmWsfxzl().getWsfszlMc() + row.getPageNo());
image.setNote(row.getQcfwDmWsfxzl().getWsfszlMc());
image.setXourceOwner(row.getNsrsbh());
image.setCollectTime(new Date());
image.setXourceGroup(xource.getXourceGroup());
[color=red]xfileSession.save(image);[/color]
XourceRelation relation = new XourceRelation();
XourceRelationId id = new XourceRelationId();
id.setXourceMain(xource);
id.setXourceFriend(image);
relation.setId(id);
relation.setTitle(image.getTitle());
xfileSession.save(relation);
[color=red]throw new Exception("xxxxxxxx");[/color]
}
// xfileSession.update(xource);
session.flush();
xfileSession.flush();
}
} catch (Exception e) {
e.printStackTrace();
addActionError(e.getLocalizedMessage());
// throw SessionFactoryUtils.convertHibernateAccessException(he);
// System.out.println(e.getLocalizedMessage());
} finally {
SessionFactoryUtils.closeSessionIfNecessary(session, sourceSessionFactory);
SessionFactoryUtils.closeSessionIfNecessary(xfileSession, xfileSessionFactory);
}
}
return SUCCESS;
}