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

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

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

    成功捷徑,貴在堅(jiān)持
    人為善,福雖未至禍已遠(yuǎn)離; 人為惡,禍雖未至福已遠(yuǎn)離
    原文來自: 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 選寶網(wǎng)an9 閱讀(1507) 評(píng)論(0)  編輯  收藏 所屬分類: JAVAFRAMEWORK
    主站蜘蛛池模板: 免费成人午夜视频| 亚洲AV永久无码精品一福利| 在线观看免费亚洲| 91香蕉国产线在线观看免费| 国产亚洲福利精品一区二区| 亚洲一级毛片免费在线观看| 亚洲AV人无码综合在线观看| 亚洲精品WWW久久久久久| 毛片免费在线视频| 免费观看国产网址你懂的| 日韩a级无码免费视频| 暖暖免费中文在线日本| 亚洲日韩国产二区无码| 亚洲乱码无限2021芒果| 亚洲综合在线视频| 亚洲不卡中文字幕无码| 亚洲精品美女久久777777| 久久精品国产精品亚洲下载 | 久久精品夜色噜噜亚洲A∨| 国产免费69成人精品视频| 女人18毛片水真多免费播放| 国产va精品免费观看| 亚洲一级毛片免费在线观看| 毛片无码免费无码播放| 91精品国产免费久久国语蜜臀| 久久精品国产免费一区| 免费成人在线电影| 免费视频成人片在线观看| 久操视频在线免费观看| 青青草无码免费一二三区| 免费A级毛片无码A∨中文字幕下载| 日本免费人成网ww555在线| 亚洲免费人成在线视频观看| a级成人毛片免费视频高清| 999zyz**站免费毛片| 免费在线中文日本| 最近免费mv在线电影| 4虎永免费最新永久免费地址| 免费三级毛片电影片| 无码中文在线二区免费| 国内大片在线免费看|