<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    成功捷徑,貴在堅持
    人為善,福雖未至禍已遠離; 人為惡,禍雖未至福已遠離
    原文來自: http://www.techfaq360.com/viewFreshers.jsp?tutorialId=840
    getCurrentSession() :
    The "current session" refers to a hibernate Session bound by hibernate behind the scenes, to the transaction scope.
    A Session is opened when getCurrentSession() is called for the first time and closed when the transaction ends.
    It is also flushed automatically before the transaction commits. You can call getCurrentSession() as often and anywhere you want as long as the transaction runs.
    To enable this strategy in your hibernate configuration:

    set hibernate.transaction.manager_lookup_class to a lookup strategy for your JEE container
    set hibernate.transaction.factory_class to org.hibernate.transaction.JTATransactionFactory

    Only the Session that you obtained with sf.getCurrentSession() is flushed and closed automatically.

    Example :
    try {
    UserTransaction tx = (UserTransaction)new InitialContext()
    .lookup("java:comp/UserTransaction");

    tx.begin();

    // Do some work
    sf.getCurrentSession().createQuery(...);
    sf.getCurrentSession().persist(...);

    tx.commit();
    }
    catch (RuntimeException e) {
    tx.rollback();
    throw e; // or display error message
    }

    openSession() :
    If you decide to use manage the Session yourself the go for sf.openSession() , you have to flush() and close() it.
    It does not flush and close() automatically.
    Example :
    UserTransaction tx = (UserTransaction)new InitialContext()
    .lookup("java:comp/UserTransaction");

    Session session = factory.openSession();

    try {
    tx.begin();

    // Do some work
    session.createQuery(...);
    session.persist(...);

    session.flush(); // Extra work you need to do

    tx.commit();
    }
    catch (RuntimeException e) {
    tx.rollback();
    throw e; // or display error message
    }
    finally {
    session.close(); // Extra work you need to do
    }
    posted on 2008-07-25 10:32 選寶網an9 閱讀(1507) 評論(0)  編輯  收藏 所屬分類: JAVAFRAMEWORK
    主站蜘蛛池模板: 免费黄色网址入口| 一级毛片免费不卡直观看| 亚洲第一页在线视频| 老司机亚洲精品影院在线观看| 中文字幕一区二区免费| 搡女人真爽免费视频大全| 免费一级毛片一级毛片aa| 亚洲视频精品在线观看| 日韩色日韩视频亚洲网站| 免费观看又污又黄在线观看| 亚洲成av人片在线看片| 羞羞视频免费网站日本| 成人男女网18免费视频| 亚洲国产精品久久网午夜| 暖暖在线视频免费视频| 77777亚洲午夜久久多人| 亚洲无人区视频大全| 久久青草国产免费观看| 亚洲国产精品13p| 亚洲成?Ⅴ人在线观看无码| 日本免费中文字幕在线看| 亚洲精品第一国产综合精品| 免费av片在线观看网站| 亚洲精品国产美女久久久| 在线观看黄片免费入口不卡| 国产成人毛片亚洲精品| 国产精品亚洲专区无码牛牛 | 日韩毛片一区视频免费| 国产免费不卡视频| 亚洲欧洲高清有无| h在线观看视频免费网站| 亚洲午夜精品在线| 嫩草影院在线免费观看| 亚洲AV无码专区在线观看成人 | 中文字幕亚洲乱码熟女一区二区| 亚洲AV色无码乱码在线观看| 国产成人3p视频免费观看| 在线精品亚洲一区二区三区 | 亚洲国产精品无码久久九九| 久久久久亚洲国产AV麻豆| 免费在线精品视频|