<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
    主站蜘蛛池模板: 青娱分类视频精品免费2| 日批视频网址免费观看| 麻豆最新国产剧情AV原创免费| 亚洲福利在线视频| 99久久99久久免费精品小说| 亚洲AV无码码潮喷在线观看| 日本免费高清视频| 久久亚洲熟女cc98cm| 97视频免费观看2区| 亚洲综合综合在线| aa级一级天堂片免费观看| 亚洲永久在线观看| 成人免费视频国产| 日韩电影免费在线观看网址| 亚洲自偷自偷图片| 一区二区免费视频| 亚洲入口无毒网址你懂的| 性一交一乱一视频免费看| 亚洲国产日韩视频观看| 国产一级淫片a视频免费观看| 污视频网站在线观看免费| 亚洲综合伊人久久大杳蕉| 日韩精品无码免费一区二区三区 | a级毛片免费在线观看| 亚洲国产综合专区在线电影| 亚洲人成在线免费观看| 亚洲精品无码专区在线| 亚洲天堂免费在线视频| 99re视频精品全部免费| 中文字幕亚洲码在线| 亚洲精品人成无码中文毛片| 男人的天堂网免费网站| 亚洲AV色吊丝无码| 亚洲国产成人久久一区WWW| 一级特黄aa毛片免费观看| 亚洲丁香婷婷综合久久| 亚洲区小说区图片区QVOD| 99爱在线观看免费完整版| 精品久久久久久亚洲综合网| 亚洲国产精品无码久久SM| 午夜精品在线免费观看|