posts - 165, comments - 198, trackbacks - 0, articles - 1
            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          學(xué)習(xí)就從官方的測試開始,但不知道怎么回事官方的測試有問題,這我就把我配置的簡單junit環(huán)境共享給大家把!
          1.下載 hibernate-annotations-3.4.0.GA 并解壓 ,cd 到解壓后目錄下
          2. $>ant junit (天知道,怎么官方出的東西測試不能通過!!)
          ?? 不要急,我們來看錯(cuò)誤 (錯(cuò)誤提示有刪減)
          ???? 錯(cuò)誤-1:$>build.xml:95: ./jdbc not found.
          ???? 解決辦法-1: $>mkdir ./jdbc
          3.? $>ant junit
          ???? 錯(cuò)誤-2:?
          ????? ./build.xml:124: The following error occurred while executing this line:
          ????? ./build.xml:126: The following error occurred while executing this line:
          ????? ./common-build.xml:349: .\src\filters\hsqldb.filter as it doesn't exist.
          ???? 解決辦法-2:
          ?????? $>mkdir? ./src/filters ;
          ?????? $>echo "" > ./src/filters/hsqldb.filter;
          4. ? $>ant junit
          ???? 錯(cuò)誤-3:
          ?????? ./build.xml:124: The following error occurred while executing this line:
          ?????? ./build.xml:126: The following error occurred while executing this line:
          ?????? ./common-build.xml:351: .\src\test-resources not found.
          ????? $>mkdir? ./src/test-resources ;
          5. ? $>ant junit
          ???? 錯(cuò)誤-4:沒有ant 錯(cuò)誤了!,但測試都為錯(cuò)誤,那我們就看看 第一個(gè)測試吧,找下原因!
          ???????? test-resources:
          ????????? [mkdir] Created dir: hibernate-anntations-3.4.0.GA\build\test-reports\hsqldb
          ????????? [echo] Running against db: hsqldb
          ????????? [junit] Running org.hibernate.test.annotations.ConfigurationTest
          ????????? [junit] Tests run: 7, Failures: 0, Errors: 6, Time elapsed: 1.218 sec
          ????????? .............
          ???? $>find . -name "ConfigurationTest.java"? #pwd /hibernate-anntations-3.4.0.GA
          ??????? ./test/org/hibernate/test/annotations/configuration/ConfigurationTest.java
          ??????? ./test/org/hibernate/test/annotations/ConfigurationTest.java
          ????? 根據(jù)路徑 org.hibernate.test.annotations.ConfigurationTest
          ????? gvim? ./test/org/hibernate/test/annotations/ConfigurationTest.java
          ????? 發(fā)現(xiàn)第20行: cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
          ????? 感覺應(yīng)該沒有配置 jdbc
          ????? gvim ./test/org/hibernate/test/annotations/hibernate.cfg.xml? #果然 沒配置
          ????? 我這就放個(gè)我的簡單配置上來(使用 hbm hsqldb 內(nèi)存數(shù)據(jù)庫測 試 ):
          <!DOCTYPE?hibernate-configuration?PUBLIC
          ????????"-//Hibernate/Hibernate?Configuration?DTD?3.0//EN"
          ????????"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"
          >
          <hibernate-configuration>
          ??
          <session-factory>
          ????????
          <property?name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
          ????????
          <property?name="connection.driver_class">org.hsqldb.jdbcDriver</property>
          ????????
          <property?name="connection.url">jdbc:hsqldb:mem:hbn_ann</property>
          ????????
          <property?name="connection.username">sa</property>
          ????????
          <property?name="connection.password"></property>
          ???
          ????????
          <mapping?resource="org/hibernate/test/annotations/Boat.hbm.xml"/>
          ????????
          <mapping?package="org.hibernate.test.annotations"/>
          ????????
          <mapping?class="org.hibernate.test.annotations.Plane"/>
          ??
          </session-factory>
          </hibernate-configuration>


          ????? 我這就是要hsqldb吧,既然上面錯(cuò)誤1有 jdbc 文件夾,那就是放 jdbc jar 的地方
          ????? $> cp ../hsqldb.jar? ./jdbc
          ???
          6. ? $>ant junit
          ???? 呵呵 測試 第一個(gè)正確了 ! (目前配置后,測試環(huán)境并不是全部都正確,比如第2個(gè)測試)
          ???? 其他測試錯(cuò)誤日志在??? .\build\test-reports\hsqldb ...
          ???? 比如第2個(gè)錯(cuò)誤 異常部分
          ????? org.hibernate.HibernateException: The dialect was not set. Set the property hibernate.dialect.
          ??? at org.hibernate.dialect.Dialect.instantiateDialect(Dialect.java:256)
          ??? at org.hibernate.dialect.Dialect.getDialect(Dialect.java:234)
          ??????? ........ 大家一邊學(xué)習(xí),一邊配置測試 環(huán)境吧。
          ??? 錯(cuò)誤日記 都會(huì)在 build\test-reports\hsqldb下

          主站蜘蛛池模板: 荃湾区| 日喀则市| 遂宁市| 鄄城县| 平湖市| 小金县| 常宁市| 莎车县| 普兰店市| 化德县| 微山县| 醴陵市| 崇州市| 江油市| 靖安县| 丽水市| 右玉县| 靖宇县| 彰化市| 巴塘县| 邵东县| 商洛市| 含山县| 尉犁县| 宿州市| 沅陵县| 正宁县| 焦作市| 扎囊县| 佛学| 旌德县| 曲靖市| 琼结县| 新营市| 昌黎县| 东乌珠穆沁旗| 天门市| 东兴市| 阆中市| 秭归县| 开化县|