标签: stalestateexception

org.hibernate.StaleStateException:批量更新从update [0]返回意外的行数; 实际行数:0; 预期:1

有时,当持久化obj时,其中一个字段太大而无法放入db字段,从而导致数据截断异常.在下面的代码中,我尝试捕获DataException并简单地清空该字段和重新保存.但是我在重新开始时遇到了异常.为什么会发生批量更新异常以及如何解决它?


 public static void save(Object obj) throws Exception{
        try{
            beginTransaction();
            getSession().save(obj);
            commitTransaction();

        }catch(Exception e){
            e.printStackTrace();
            rollbackTransaction();
            throw e;
        }finally{
            closeSession(); //not needed, session obtained from sf.getCurrentSession() will auto close
        }
    }   
 public static void saveXXX(XXX rec){

        try {
            save(rec);
        } catch (org.hibernate.exception.DataException e) {
            e.printStackTrace();

            saveXXX(rec, e); //causes an exception      
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
    private static void saveXXX(WhoisRecord rec, DataException e) {
        rec.setField(""); //empty out the problem field
        saveXXX(rec);

例外:

org.hibernate.StaleStateException:批量更新从update [0]返回意外的行数; 实际行数:0; 预期:1
    在org.hibernate.jdbc.Expectations $ …

java mysql hibernate stalestateexception

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

hibernate ×1

java ×1

mysql ×1

stalestateexception ×1