Hibernate wasrolledback method: judge whether the transaction is rolled back
                                        
                    •
                    Java                                    
                wasRolledBack()
Example
try{
  tx = session.beginTransaction();  //开启事务
  UserForm uf = new UserForm();  //定义JavaBean对象
  uf.setUsername(username);  //设置对象属性
  uf.setPwd(pwd);
  session.saveOrUpdate(uf);
  tx.commit();  //提交事务
}catch(Exception e){
  if(tx!=null){
    if(tx.wasRolledBack()){
      System.out.println("事务已经回滚");
    }else{
      System.out.println("事务没有回滚");
    }
    tx.rollback();//回滚事务
    if(tx.wasRolledBack()){
      System.out.println("事务已经回滚");
    }else{
      System.out.println("事务没有回滚");
    }
  }
}
                
                            The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
                        
                                            
                        THE END
                    
                    
                    
                                                        二维码
                        
                        
                                                
                        