1. hibernate need an active transaction
2. you should roll back the transaction immediately after any db error!
3. hibernate doesn't support save point..so, in you case.. you can only use begintran & commit inside your for clause and use try..catch to make sure that one failed operation won't stop your for cluase.
2. you should roll back the transaction immediately after any db error!
3. hibernate doesn't support save point..so, in you case.. you can only use begintran & commit inside your for clause and use try..catch to make sure that one failed operation won't stop your for cluase.
解决方案 »
- 关于oracle存储过程调用java执行系统命令的疑问
- 急急急ssh下如何设计触发一个action,实现登录主页,主页数据来自服务器,像sina主页那种。。
- 分层的困惑。写多了才发现,我把业务逻辑写action里面了,求解决方案
- java.lang.UnsupportedOperationException报错
- DatabaseMetaData.getTables 的问题
- Hibernate问题!
- 200分问问题(1)
- linux 上的Jbuilder 9的序列号谁有
- 在开发ejb中,本地(local)接口、远程(Remote)接口、Home接口、LocalHome接口这些是放在都放在应用服务器中吗,需不需要放在客服端中?
- 急:关于JMS-Implemented WebLogic Web Services的问题!!
- 关于hibernate 配置二级缓存的一个小问题
- hibernate循环update()的问题
//根据ID取得子类树
List subCategorys=new ArrayList();
public List getSubCategorysTree(int ID){
List list = new ArrayList();
try {
session = HibernateUtil.getSession();
tx = session.beginTransaction();
String hql = "from Category where fatherID=" + ID;
list = session.createQuery(hql).list();
tx.commit();
} catch (Exception e) {
tx.rollback();
log.error("生成ID为 " + ID + " 的子类树失败!", e);
} finally {
HibernateUtil.closeSession();
}
try {
for (int i = 0; i < list.size(); i++) {
Category categoryPO = (Category) list.get(i);
CategoryVO categoryVO = new CategoryVO();
BeanUtils.copyProperties(categoryVO, categoryPO);
subCategorys.add(categoryVO);
this.getSubCategorysTree(categoryPO.getID());
}
} catch (Exception e) {
log.error("生成ID为 " + ID + " 的子类树失败!", e);
}
return subCategorys;
}