[導入][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”很容易報一下錯誤:
因為“mvn appfuse:gen -Dentity=Name”一次只支持一個Entity(這樣執行會很累啊),會找不到對應的關聯者。這時,我們需要手動的將有關聯關系的Entity都加入到hibernate.cfg.xml里,再執行就可以了。
3。執行“mvn jetty:run-war”時,會根據POJO先刪除數據庫里的表再重建,如果不想對數據進行操作可以修改pom.xml,將drop熟悉修改為false。不過執行“mvn jetty:run-war”仍然會執行建表操作,出現大量的錯誤日志,不過沒有影響。
<dbunit.operation.type>NONE</dbunit.operation.type>
文章來源: http://heyday.blogcn.com/diary,14897952.shtml
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)
......
[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>

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

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

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