后面加了conn.commit();我自己建了一个类,测试通过了,
但是在tomcat中数据却没有被提交,后面一部分的hibernate代码删掉就可以,不知道是什么原因,代码如下: //创建一个session
CommonDao l_commonDao = new HibernateCommonDaoImpl();
//获得该回复的主题
Topic l_topic = (Topic) p_relapse.getTopic();
//更新主体或者投票的回帖数
TopicBusiness to=TopicBusiness.getBusiness();
Integer i=l_topic.getReplayNum();
int newno=i.intValue()+1;
l_topic.setReplayNum(new Integer(newno));
to.update(l_topic);
//获得创建该回复的时间
p_relapse.setRelapseTime(Tool.getCurrentTime("yyyy-MM-dd HH:mm:ss"));
//下列修改操作人的等级和分数
//获得创建主题的用户对象
Account l_account = p_relapse.getReplayAccount();
//获得等级业务处理器
GradeBusiness l_gradeBusiness = GradeBusiness.getBusiness();
//给用户设置分数?????
l_account.setNumeric(new Integer(l_account.getNumeric().intValue()+ Globe.REANNOUNCE_CLUE));
//根据分数得到等级
Grade l_grade = (Grade) l_gradeBusiness.confirmGrade(l_account.getNumeric(), l_commonDao);
//跟用户设置等级
l_account.setGrade(l_grade);
//获得帐号业务处理器
AccountBusiness l_accountBusiness = AccountBusiness.getBusiness();
p_relapse.setRelapseContextClob(Hibernate.createClob(" "));
java.io.Writer pw = null;
try {
l_commonDao.getSession().connection().setAutoCommit(false);
//下列持久化回复对象
l_commonDao.save(p_relapse);
l_commonDao.flush();
l_commonDao.getSession().refresh(p_relapse,LockMode.UPGRADE);
CLOB l_clob = (oracle.sql.CLOB) ( (org.hibernate.lob.SerializableClob) p_relapse.getRelapseContextClob() ).getWrappedClob();
pw = l_clob.getCharacterOutputStream();
pw.write(p_relapse.getRelapseContext());
pw.close();
l_commonDao.getSession().connection().commit();
} catch (Exception e) {
try {
// TODO 自动生成 catch 块
if(pw != null)
pw.close();
} catch (IOException e1) {
logger.error(e1);
pw = null;
}
logger.error(e);
l_commonDao.close();
throw new PersistenetException(" 添加一个帖子时异常,方法T Relapse save(Relapse p_relapse,Long p_topicId)");
}
//更新用户的分数和等级
l_accountBusiness.update(l_account);
//session关闭
l_commonDao.close();
return p_relapse;
但是在tomcat中数据却没有被提交,后面一部分的hibernate代码删掉就可以,不知道是什么原因,代码如下: //创建一个session
CommonDao l_commonDao = new HibernateCommonDaoImpl();
//获得该回复的主题
Topic l_topic = (Topic) p_relapse.getTopic();
//更新主体或者投票的回帖数
TopicBusiness to=TopicBusiness.getBusiness();
Integer i=l_topic.getReplayNum();
int newno=i.intValue()+1;
l_topic.setReplayNum(new Integer(newno));
to.update(l_topic);
//获得创建该回复的时间
p_relapse.setRelapseTime(Tool.getCurrentTime("yyyy-MM-dd HH:mm:ss"));
//下列修改操作人的等级和分数
//获得创建主题的用户对象
Account l_account = p_relapse.getReplayAccount();
//获得等级业务处理器
GradeBusiness l_gradeBusiness = GradeBusiness.getBusiness();
//给用户设置分数?????
l_account.setNumeric(new Integer(l_account.getNumeric().intValue()+ Globe.REANNOUNCE_CLUE));
//根据分数得到等级
Grade l_grade = (Grade) l_gradeBusiness.confirmGrade(l_account.getNumeric(), l_commonDao);
//跟用户设置等级
l_account.setGrade(l_grade);
//获得帐号业务处理器
AccountBusiness l_accountBusiness = AccountBusiness.getBusiness();
p_relapse.setRelapseContextClob(Hibernate.createClob(" "));
java.io.Writer pw = null;
try {
l_commonDao.getSession().connection().setAutoCommit(false);
//下列持久化回复对象
l_commonDao.save(p_relapse);
l_commonDao.flush();
l_commonDao.getSession().refresh(p_relapse,LockMode.UPGRADE);
CLOB l_clob = (oracle.sql.CLOB) ( (org.hibernate.lob.SerializableClob) p_relapse.getRelapseContextClob() ).getWrappedClob();
pw = l_clob.getCharacterOutputStream();
pw.write(p_relapse.getRelapseContext());
pw.close();
l_commonDao.getSession().connection().commit();
} catch (Exception e) {
try {
// TODO 自动生成 catch 块
if(pw != null)
pw.close();
} catch (IOException e1) {
logger.error(e1);
pw = null;
}
logger.error(e);
l_commonDao.close();
throw new PersistenetException(" 添加一个帖子时异常,方法T Relapse save(Relapse p_relapse,Long p_topicId)");
}
//更新用户的分数和等级
l_accountBusiness.update(l_account);
//session关闭
l_commonDao.close();
return p_relapse;
TopicBusiness to=TopicBusiness.getBusiness();
Integer i=l_topic.getReplayNum();
int newno=i.intValue()+1;
l_topic.setReplayNum(new Integer(newno));
to.update(l_topic);
这部分原来是用jdbc的,就是第一篇的代码,后面加了事务的提交,单独运行数据可以更新,但是放到这个环境里就不行了。l_commonDao是hibernate的工具类