<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
    主站蜘蛛池模板: 亚洲成网777777国产精品| 4444www免费看| 男人的天堂亚洲一区二区三区| 欧洲亚洲国产清在高| 国产精品玖玖美女张开腿让男人桶爽免费看 | tom影院亚洲国产一区二区| AAA日本高清在线播放免费观看| 亚洲精品无码久久久久AV麻豆| 成人区精品一区二区不卡亚洲| 国产精品免费观看久久| 在线观看亚洲AV每日更新无码| 毛片免费在线观看网站| 亚洲第一第二第三第四第五第六| 成年女人色毛片免费看| 亚洲AV成人无码网天堂| 亚洲第一网站男人都懂| 久久久久久噜噜精品免费直播| 亚洲中文久久精品无码ww16| 国产色无码精品视频免费| 精品亚洲aⅴ在线观看| 91成年人免费视频| 亚洲av无码专区国产不乱码| 免费在线观看一级毛片| 免费无码H肉动漫在线观看麻豆| 亚洲免费在线播放| 成年女人毛片免费播放视频m| 精品国产亚洲一区二区三区在线观看 | 亚洲精品福利网站| 免费观看的毛片手机视频| 特级毛片A级毛片免费播放| 国产成人亚洲综合色影视| 最近免费中文字幕高清大全 | 国产精品亚洲一区二区麻豆| 亚洲国产成人久久一区WWW| 在线看片免费人成视频福利| 91亚洲性爱在线视频| 亚洲AV无码一区二区三区国产| 少妇性饥渴无码A区免费| 亚洲中文精品久久久久久不卡| 五月天婷亚洲天综合网精品偷| 少妇人妻偷人精品免费视频|