Hibernate手动事务管理问题

[code="java"]
public void deleteMoreFlowCards(String[] vouNos) {
String tempVouNos = VouNoGenerator.getString(vouNos, ",");

    String sql = "delete from t_flow_card  where vouNo in("+tempVouNos+")";
    String flowCardDetailSql = "delete from t_flow_card_detail where vou_no in("+tempVouNos+")";

    [color=red]此处使用getCurrentSession,就抱Transaction not successfully started
              openSession和getCurrentSession的区别是,getCurrentSession提交后,session会自动关闭
                 而openSession不会,需手动提交,可和这没关系啊。[/color]        
               Session session = getHibernateTemplate().getSessionFactory().openSession();
    //Session session = getHibernateTemplate().getSessionFactory().getCurrentSession();
    //SQLQuery sqlQuery = session.createSQLQuery(sql);

    Connection conn = null;
    PreparedStatement psmt=null;
    Transaction tx = null;

    try {
        //conn.setAutoCommit(false);
        tx = session.beginTransaction();
        conn = session.connection();

        psmt = conn.prepareStatement(flowCardDetailSql);
        psmt.executeUpdate();

        psmt = conn.prepareStatement(sql);
        psmt.executeUpdate();

System.out.println("commit"+conn.getAutoCommit());

        //conn.commit();
        tx.commit();

    } catch (SQLException e) {
        e.printStackTrace();

        if(tx != null){
            tx.rollback();
        }
        /*if(conn != null){
            try {
                conn.rollback();
            } catch (SQLException e1) {
                e1.printStackTrace();
            }
        }*/
    }finally{
        try {
            //conn.setAutoCommit(true);
            psmt.close();
            conn.close();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

    //sqlQuery.executeUpdate();



}

[/code]

描述见红色字体

补充:Hibernate 使用jdbc进行批量删除时,事务管理是使用Connection来管理还是使用Hibernate封装好的Transaction来管理呢?请给建议。谢谢。

字不变红,再补:
[color=red]此处使用getCurrentSession,就抱Transaction not successfully started
openSession和getCurrentSession的区别是,getCurrentSession提交后,session会自动关闭
而openSession不会,需手动提交,可和这没关系啊。[/color]

Session session = getHibernateTemplate().getSessionFactory().openSession();

[b]问题补充:[/b]
[color=red]
getCurrentSession就指得到当前可用的session,如果压根就没开启事务,
[/color]

我事务管理采用的spring的事务管理,不要我手动开啊,

[color=red]
getCurrentSession就指得到当前可用的session
[/color],如果没有会开新的吧

这文章 说得不错
http://blog.csdn.net/LoveYouT/archive/2009/05/17/4193894.aspx

getCurrentSession就指得到当前可用的session,如果压根就没开启事务,自然是报Transaction not successfully started

openSession()就是明确让它启动一个事务

hibernate的事务管理底层还是使用Connection来管理嘛,

只不过它会推迟到最后,比如先进行脏检查等等