使用了hibernate 乐观锁
代码如下:DAOpublic void updateVersion(Object obj)throws StaleObjectStateException {
Session session = getSession();
try{
session.update(obj);
}catch (StaleObjectStateException e) {
throw e;
}finally{
releaseSession(session);
}
}
调用者try {
accountdetaildao.updateVersion(detail);
} catch (StaleObjectStateException e) {
e.printStackTrace();
System.out.println("被其它用户修改!"); //后台没打印`
}public void updateVersion(Object obj)throws StaleObjectStateException 我抛出了它
但调用accountdetaildao.updateVersion(detail);没有强制我try catch它!所以StaleObjectStateException继承于RuntimeException
它为运行期异常- -!  
运行期间异常如何处理请高手帮忙!谢谢`
我想给用户一个友好的提示.

解决方案 »

  1.   

       public void updateVersion(Object obj)throws StaleObjectStateException?
       你里面都catch怎么这里还throws啊
      

  2.   


    是的我想调用者try它`然后返回出去!
      

  3.   

    public void updateVersion(Object obj)throws StaleObjectStateException {
            Session session = getSession();
            try{
                session.update(obj);
            }finally{
                releaseSession(session);
            }
        }
    try {
                        accountdetaildao.updateVersion(detail);
                    } catch (StaleObjectStateException e) {
                        e.printStackTrace();
                        throw new BizException("数据被修改");
                    }错误页面遇到bizException()就将错误信息显示给用户
      

  4.   


    感谢``我用的是Xfire+hibernate+spring
    不是ssh项目`没有页面`
      

  5.   

    public class MyStaleObjectStateException extends RuntimeException{
    public MyStaleObjectStateException() {
    super();/
    }
    public MyStaleObjectStateException(String str){
    super(str);
    }}
     
     public void updateVersion(Object obj) {
            Session session = getSession();
            try{
                session.update(obj);
            }catch (StaleObjectStateException e) {
                throw new MyStaleObjectStateException();
            }finally{
                releaseSession(session);
            }
        }          如果是我,我会这样做
      

  6.   

    那就是没有抛出StaleObjectStateException 异常了,设置一下断点看一下就都知道了
      

  7.   


    后台打印org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.htky.po.TabBalanceDetail#60369871A3F247FC8EEDFAA25DC2B478]已经出异常了``
      

  8.   


    try {
                        accountdetaildao.updateVersion(detail);
                    } catch (StaleObjectStateException e) {
                        e.printStackTrace();
                       //这样写,下面这条语句肯定不会执行啊
                        System.out.println("被其它用户修改!"); 
                    }
                 
      

  9.   

    由于hibernate将异常 封装了,一般都继承RuntimeException