<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
    主站蜘蛛池模板: 妞干网免费视频在线观看| 久久精品无码精品免费专区| 成年男女免费视频网站| 亚洲日本在线免费观看| 精品福利一区二区三区免费视频| 亚洲视频在线免费观看| 5g影院5g天天爽永久免费影院| 亚洲视频在线观看地址| 亚洲黄色免费观看| 亚洲乱码日产精品BD在线观看| 国产精品视频永久免费播放| 一本色道久久88亚洲精品综合| 日美韩电影免费看| 五月天国产成人AV免费观看| 国产偷国产偷亚洲清高动态图| 亚洲不卡无码av中文字幕| 夜夜爽妓女8888视频免费观看| 亚洲午夜国产精品无码| 亚洲另类无码专区丝袜| 国产资源免费观看| 亚洲午夜久久久久久尤物| 免费无码又爽又刺激高潮的视频| 亚洲无删减国产精品一区| 99在线精品免费视频九九视| 亚洲午夜精品一区二区麻豆| 亚洲国产综合无码一区二区二三区| 中文日本免费高清| 亚洲午夜精品一区二区公牛电影院| 成年女人色毛片免费看| 亚洲日韩在线观看免费视频| 免费在线观看污网站| 特级做A爰片毛片免费看无码 | 亚洲片一区二区三区| 久久永久免费人妻精品| 最新国产精品亚洲| 国产亚洲一区二区三区在线不卡| 黄页视频在线观看免费| 亚洲成A人片在线观看无码不卡| 亚洲中文无码永久免费| 国产va免费观看| 亚洲人成人77777在线播放|