Hibernate事务回滚代码

if(i%1000==0){

try{
stmt1.executeBatch();
session.getTransaction().commit();
stmt1.clearBatch();

session.beginTransaction();
stmt2.executeBatch();
session.getTransaction().commit();
stmt2.clearBatch();
session.beginTransaction();

}catch(SQLException e){
e.printStackTrace();
try{
if(conn != null){
conn.rollback();
}
session.getTransaction().rollback();
}catch(SQLException se){
se.printStackTrace();
}
}finally{
if(stmt1!=null){
try {
stmt1.close();
stmt1=null;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

if(stmt2!=null){
try {
stmt2.close();
stmt2=null;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

if(conn!=null){
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
conn=null;
}
}
}

你可能感兴趣的:(Java)