[導入][AppFuse] AppFuse使用手記--試例(二) [原]

              1。可以使用“mvn appfuse:gen-model”依據數據庫的表生成POJO,如果你非常熟悉JPA也可以手寫POJO,位置在DgroupId.model下。再通過“mvn appfuse:gen -Dentity=Name”生成CURD類。
             
              2。如果POJO不存在關聯關系,那么執行“mvn appfuse:gen -Dentity=Name”時,如果Entity沒有在hibernate.cfg.xml里,則會自動增加。如果存在關聯關系,在POJO里注釋了@OneToMany或者 @ManyToMany,直接執行“mvn appfuse:gen -Dentity=Name”很容易報一下錯誤:
              [INFO] ------------------------------------------------------------------------
              [ERROR] FATAL ERROR
              [INFO] ------------------------------------------------------------------------
              [INFO] Use of @OneToMany or @ManyToMany targeting an unmapped class: com.reda.app.model.CompanyType.
              companies[com.reda.app.model.Company]
              [INFO] ------------------------------------------------------------------------
              [INFO] Trace
              org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: com
              .reda.app.model.CompanyType.companies[com.reda.app.model.Company]
                      at org.hibernate.cfg.annotations.CollectionBinder.bindManyToManySecondPass(CollectionBinder.
              java:979)
              ......
            
              因為“mvn appfuse:gen -Dentity=Name”一次只支持一個Entity(這樣執行會很累啊),會找不到對應的關聯者。這時,我們需要手動的將有關聯關系的Entity都加入到hibernate.cfg.xml里,再執行就可以了。
             
              3。執行“mvn jetty:run-war”時,會根據POJO先刪除數據庫里的表再重建,如果不想對數據進行操作可以修改pom.xml,將drop熟悉修改為false。不過執行“mvn jetty:run-war”仍然會執行建表操作,出現大量的錯誤日志,不過沒有影響。
           1    <groupId>org.codehaus.mojo</groupId>
           2    <artifactId>hibernate3-maven-plugin</artifactId>
           3    <version>2.0-alpha-2</version>
           4    <configuration>
           5        <components>
           6            <component>
           7                <name>hbm2ddl</name>
           8                <implementation>annotationconfiguration</implementation>
           9                <!-- Use 'jpaconfiguration' if you're using JPA. -->
          10                <!--<implementation>jpaconfiguration</implementation>-->
          11            </component>
          12        </components>
          13        <componentProperties>
          14            <drop>false</drop>
          15            <jdk5>true</jdk5>
          16            <propertyfile>target/classes/jdbc.properties</propertyfile>
          17            <skip>${maven.test.skip}</skip>
          18        </componentProperties>
          19    </configuration>


              4。執行“mvn jetty:run-war”時,會清空數據表的數據并插入默認的數據,默認的數據在%PROJECT_HOME%\src\main\resources\default-data.xml配置,這個很討厭。修改pom.xml可以屏蔽這部分操作。

           <dbunit.operation.type>NONE</dbunit.operation.type>

              5。執行“mvn jetty:run-war”時,會執行測試,很XP喔。如果測試通不過服務就起不來。找了很多配置似乎都跳不過這一步。
              appfuse:gen-model時生成的POJO,自增列不會生成@Column注釋,就容易報以下的錯誤,增加相應的@Column就可以了: 

             Unknown column 'this_.typeId' in 'field list'
              另外生成的測試類也不是直接可以測試通過的,還要針對數據做一些修改。如果POJO存在關聯關系,測試類的關聯部分也需要進行手動設值的。


          文章來源: http://heyday.blogcn.com/diary,14897952.shtml

          posted on 2008-05-04 20:57 不同樊響 閱讀(930) 評論(1)  編輯  收藏

          評論

          # re: [導入][AppFuse] AppFuse使用手記--試例(二) [原] 2013-05-13 18:19 tony chan

          最近研究appfuse,出了點問題,看到你的博客,很有幫助,謝謝~  回復  更多評論   


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          導航

          <2008年5月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          統計

          常用鏈接

          留言簿(2)

          隨筆檔案(23)

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 巧家县| 孟村| 通道| 金平| 开江县| 临颍县| 兴山县| 长武县| 抚顺县| 紫金县| 贵阳市| 凤庆县| 日喀则市| 嫩江县| 六安市| 兰西县| 红桥区| 裕民县| 山丹县| 沅江市| 浦城县| 屏边| 财经| 浪卡子县| 个旧市| 玉山县| 印江| 荣昌县| 江城| 册亨县| 双辽市| 大英县| 武强县| 余干县| 砚山县| 蒲城县| 额敏县| 张家口市| 新乡市| 石棉县| 南木林县|