<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
    主站蜘蛛池模板: 国产成人免费福利网站| 国产免费A∨在线播放| 性xxxxx免费视频播放| 中文字幕亚洲色图| 99免费在线观看视频| 亚洲成人免费在线| 222www免费视频| 亚洲精品二三区伊人久久| 日韩av无码成人无码免费| 亚洲综合色7777情网站777| 成年人视频在线观看免费| 亚洲成a人片在线不卡一二三区 | a一级毛片免费高清在线| 亚洲第一永久AV网站久久精品男人的天堂AV| 美国毛片亚洲社区在线观看| 四虎影永久在线高清免费| 无码精品人妻一区二区三区免费| 亚洲AV之男人的天堂| 中文字幕视频免费在线观看| 久久精品国产精品亚洲蜜月| h片在线免费观看| 亚洲人av高清无码| 亚洲日韩人妻第一页| 免费在线看黄网站| 亚洲成av人片不卡无码| 四虎成人精品一区二区免费网站| 免费一区二区无码视频在线播放| 亚洲日韩v无码中文字幕 | 女人体1963午夜免费视频| 亚洲国产精品一区二区久| 女人张开腿等男人桶免费视频 | 国产成A人亚洲精V品无码性色 | 在线美女免费观看网站h| 日韩亚洲国产综合高清| 亚洲黄片手机免费观看| 91在线老王精品免费播放| 亚洲国产高清国产拍精品| 亚洲无人区午夜福利码高清完整版| 免费国产在线视频| 亚洲AV无码专区在线电影成人| 亚洲欧洲成人精品香蕉网|