<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无码成人网站在线观看| 日本三级2019在线观看免费| 中文字幕亚洲精品资源网| 久久香蕉国产线看免费| 亚洲AV无码专区电影在线观看| 久久九九久精品国产免费直播| 久久精品国产亚洲一区二区三区| 又粗又长又爽又长黄免费视频| 亚洲成a人片在线观看久| 丰满妇女做a级毛片免费观看| 亚洲午夜国产片在线观看| 精品国产污污免费网站入口| 国产国拍精品亚洲AV片| av永久免费网站在线观看| 亚洲日本在线观看| 很黄很黄的网站免费的| 国产亚洲精品成人AA片| 免费人成网站在线播放| 国产成人自产拍免费视频| 亚洲AV中文无码乱人伦下载| 亚洲免费视频播放| 亚洲色大网站WWW永久网站| 免费在线观看黄网| 三上悠亚电影全集免费| 亚洲系列中文字幕| 曰皮全部过程视频免费国产30分钟| 日本一区二区三区在线视频观看免费 | 亚洲精品成a人在线观看| 国产日韩AV免费无码一区二区| 亚洲伦理一区二区| 日本高清免费aaaaa大片视频| 一级一级一级毛片免费毛片| 亚洲视频免费在线观看| 日韩黄色免费观看| 在线涩涩免费观看国产精品| 久久久久se色偷偷亚洲精品av| 亚洲AⅤ永久无码精品AA| 91精品国产免费网站| 婷婷亚洲综合一区二区|