[导入][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 不同樊响 阅读(823) 评论(1)  编辑  收藏

评论

# re: [导入][AppFuse] AppFuse使用手记--试例(二) [原] 2013-05-13 18:19 tony chan

最近研究appfuse,出了点问题,看到你的博客,很有帮助,谢谢~  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航:
 

导航

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

统计

常用链接

留言簿(2)

随笔档案(23)

搜索

最新评论

阅读排行榜

评论排行榜