• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
    • 軟件測試技術
    • 軟件測試博客
    • 軟件測試視頻
    • 開源軟件測試技術
    • 軟件測試論壇
    • 軟件測試沙龍
    • 軟件測試資料下載
    • 軟件測試雜志
    • 軟件測試人才招聘
      暫時沒有公告

    字號: | 推薦給好友 上一篇 | 下一篇

    插入式持久性提供者的承諾:Kodo、OpenJPA和Hibernate

    發布: 2008-6-25 14:30 | 作者: 不詳 | 來源: 測試時代編輯整理 | 查看: 527次 | 進入軟件測試論壇討論

    領測軟件測試網


    org.hibernate.HibernateException: The chosen transaction strategy requires access to the JTA TransactionManager
            at org.hibernate.impl.SessionFactoryImpl.(SessionFactoryImpl.java:329)
            at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
            at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915)
            at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:730)
            at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:127)
      這個錯誤消息是有意義的。persistence.xml的配置沒有指定事務類型。容器環境中默認的事務類型是JTA。當未將它被告知Weblogic Server的事務管理器的信息時,Hibernate會有所抱怨。配置Hibernate使之明確使用本地事務怎么樣?我編輯了persistence.xml

    <persistence-unit name="test" transaction-type="RESOURCE_LOCAL">   然后再次運行構建腳本,它將部署并運行JUnit測試,

    $ ant -Dprovider=hibernate  讓我驚喜的是,這次部署的應用程序沒有出錯。但是測試沒有成功。

       [echo] Running JUnit Test: junit.TestJPAService ...
       [junit] Logical Persistence Provider is [hibernate]
       [junit] Actual  Persistence Provider is [org.hibernate.impl.SessionImpl]
       [junit] Test junit.TestJPAService FAILED
       [echo] *** ERROR: There are test failures. Output is shown below
       [concat] Testsuite: junit.TestJPAService
       [concat] Tests run: 2, Failures: 1, Errors: 0, Time elapsed: 2.934 sec
       [concat]
       [concat] ------------- Standard Output ---------------
       [concat] Contacting server t3://localhost:7001 as weblogic for JPAService
       [concat] ------------- ---------------- ---------------
       [concat] ------------- Standard Error -----------------
       [concat] Logical Persistence Provider is [hibernate]
       [concat] Actual  Persistence Provider is [org.hibernate.impl.SessionImpl]
       [concat] ------------- ---------------- ---------------
       [concat] Testcase: testLog(junit.TestJPAService):    FAILED
       [concat] Message is not assigned any identifier
       [concat] junit.framework.AssertionFailedError: Message is not assigned any identifier
       [concat]     at junit.TestJPAService.testLog(Unknown Source)
      通過了一個測試。用org.hibernate.impl.SessionImpl,確切地說,是它的代理對這個bean進行了注入。

      但是,為什么向 Message實例分配標識符沒有成功?

       這只不過因為我們設計bean使用容器管理事務,而現在卻配置為使用本地事務。所以我們的bean代碼和容器都沒有提交事務,而且因為標識值指定為由提供者賦值(見Message.java中的@Id注釋)并且由Hibernate利用數據庫列的自動增量特性為標識賦值――所以也沒有提交表示沒有標識值賦值。

       當然,我們能夠在JPAServiceBean.log()方法中添加明確的事務分界;但這不是解決方案。在容器環境中,我們傾向于使用容器管理的事務,傾向于配置持久性單元使用JTA。

      如何告知Hibernate使用Weblogic事務管理器并將它的事務與容器事務結合起來?我通過Google進行了幾分鐘的搜索找到了答案。向persistence.xml添加以下屬性。

    延伸閱讀

    文章來源于領測軟件測試網 http://www.kjueaiud.com/


    關于領測軟件測試網 | 領測軟件測試網合作伙伴 | 廣告服務 | 投稿指南 | 聯系我們 | 網站地圖 | 友情鏈接
    版權所有(C) 2003-2010 TestAge(領測軟件測試網)|領測國際科技(北京)有限公司|軟件測試工程師培訓網 All Rights Reserved
    北京市海淀區中關村南大街9號北京理工科技大廈1402室 京ICP備10010545號-5
    技術支持和業務聯系:info@testage.com.cn 電話:010-51297073

    軟件測試 | 領測國際ISTQBISTQB官網TMMiTMMi認證國際軟件測試工程師認證領測軟件測試網

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>