<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| 亚洲日本在线看片| 99在线视频免费观看| 亚洲好看的理论片电影| 久久WWW免费人成人片| 男女猛烈激情xx00免费视频| 亚洲欧洲日韩不卡| 处破痛哭A√18成年片免费| 国产福利在线观看永久免费| 久久精品国产亚洲av麻豆小说 | 国产特级淫片免费看| 99在线视频免费观看| 亚洲色www永久网站| 亚洲中文字幕久久精品无码APP | 国产精品亚洲а∨无码播放| 一二三四视频在线观看中文版免费| 一级看片免费视频| 国产.亚洲.欧洲在线| 亚洲色无码专区在线观看| 妞干网在线免费视频| 日韩电影免费在线观看| 国产精品亚洲va在线观看| 久久夜色精品国产噜噜亚洲AV| 国产一级一片免费播放i| 日韩免费无码一区二区三区| 鲁啊鲁在线视频免费播放| 亚洲欧洲高清有无| 亚洲Av无码专区国产乱码DVD| 国产午夜免费秋霞影院| 久久99九九国产免费看小说| 久久免费精品一区二区| 一级毛片正片免费视频手机看 | 91福利免费网站在线观看| 久久精品亚洲日本波多野结衣 | 国产亚洲日韩在线a不卡| 亚洲成a人片7777| 久久青青成人亚洲精品| 激情97综合亚洲色婷婷五| 日本中文一区二区三区亚洲| 女人18毛片a级毛片免费| 国产成人精品免费视|