<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 閱讀(1494) 評論(0)  編輯  收藏 所屬分類: JAVAFRAMEWORK
    主站蜘蛛池模板: 亚洲婷婷综合色高清在线| 国产成人一区二区三区免费视频 | 亚洲成年网站在线观看| 8x8x华人永久免费视频| 久久久久亚洲AV综合波多野结衣| 国产成人综合亚洲一区| 国产做床爱无遮挡免费视频| 亚洲国产成人久久综合| 国产免费观看网站| 永久免费精品影视网站| 亚洲人成影院在线无码观看| eeuss影院www天堂免费| 亚洲精品无码不卡在线播放HE| 中文字幕不卡高清免费| 亚洲av中文无码乱人伦在线播放| 免费在线观看一级片| 久久久亚洲欧洲日产国码aⅴ| 精品国产免费人成电影在线观看| 亚洲国产精品成人精品小说| 最新中文字幕电影免费观看| 亚洲av无码一区二区三区四区| 免费一级毛片在级播放| 在线免费观看伊人三级电影| 亚洲男人都懂得羞羞网站| 999国内精品永久免费观看| 亚洲中文字幕无码中文| 亚洲黄黄黄网站在线观看| 精品国产免费一区二区三区香蕉| 亚洲短视频在线观看| 国产精品久久久久影院免费| 国产乱子伦精品免费视频| 亚洲最大成人网色| 免费鲁丝片一级观看| 久久久久久久国产免费看| 亚洲视频免费一区| 国产国产人免费视频成69大陆| 中文在线免费观看| 亚洲中文字幕久久无码| 亚洲午夜国产精品无码 | 久久国产乱子伦免费精品| 亚洲国产成人精品无码区花野真一 |