Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > Java > read-Atleap-8-实做ContentField
【标  题】:read-Atleap-8-实做ContentField
【关键字】:ie,C,ld,read,Atleap
【来  源】:BLOG.CSDN.NET

read-Atleap-8-实做ContentField

Your Ad Here

v 实做ContentField

Ø 手工生成ContentField.java POJO

Ø 运用AppGen工具自动生成代码,具体原理请参见ReadAppFuse系列

Ant install -Dmodel.name=ContentField -Dmodel.name.lowercase=contentfield

在这里我将AppGen提供的installinstall-detailed任务合并为了一个,以便使用方

便,合并很简单:

<targetname="install"depends="install-src-generic,install-src-detailed,install-other"/

    1)运行DAO测试

        ant test-dao -Dtestcase=ContentFieldDAO

    © 运行报错

        test-dao:

     [echo] Testing dao...

    [junit] Testsuite: org.dudu.dao.ContentFieldDAOTest

    [junit] Tests run: 5, Failures: 1, Errors: 4, Time elapsed: 1.412 sec

    [junit] ------------- Standard Output ---------------

    [junit] Testcase: testAddContentField(org.dudu.dao.ContentFieldDAOTest):

Caused an ERROR

    [junit] Unknown entity: org.dudu.model.ContentField; nested exception is org

.hibernate.MappingException: Unknown entity: org.dudu.model.ContentField

    © 错误分析

        错误提示为找不到org.dudu.model.ContentField

    © 错误原因

        AppGen生成的配置文件applicationContext-hibernate.xml

没有为SessionFactory添加POJO映射配置

    © 解决方法

        手工添加配置信息

        <beans>

    <!-- Hibernate SessionFactory -->

    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

        <property name="dataSource"><ref bean="dataSource"/></property>

        <property name="mappingResources">

            <list>

                <value>org/dudu/model/Role.hbm.xml</value>

                <value>org/dudu/model/User.hbm.xml</value>

                <value>org/dudu/model/UserCookie.hbm.xml</value>

                <value>org/dudu/model/ContentField.hbm.xml</value>

                <value>org/dudu/model/ContentFieldValue.hbm.xml</value>

                <value>org/dudu/model/ContentLocale.hbm.xml</value>

                <value>org/dudu/model/Localizable.hbm.xml</value>

                <value>org/dudu/model/ResourceData.hbm.xml</value>

            </list>

           

    </beans>

    2)再次运行DAO测试

        ant test-dao -Dtestcase=ContentFieldDAO

        © 运行报错

            test-dao:

     [echo] Testing dao...

    [junit] Testsuite: org.dudu.dao.ContentFieldDAOTest

    [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec

    [junit] Null Test:  Caused an ERROR

    [junit] null

    [junit] java.lang.ExceptionInInitializerError

    [junit]     at java.lang.Class.forName0(Native Method)

    [junit]     at java.lang.Class.forName(Class.java:164)

    [junit] Caused by: org.springframework.beans.factory.BeanCreationException:

Error creating bean with name 'sessionFactory' defined in file [E:\dudu-src\buil

d\dao\gen\META-INF\applicationContext-hibernate.xml]: Initialization of bean fai

led; nested exception is org.hibernate.MappingException: Association references

unmapped class: org.dudu.model.ContentDocument

        © 错误原因

            不能映射到org.dudu.model.ContentDocument

            从代码中可知ContentDocument继承于ContentResourcehibernate工具生成

            映射文件时,不会为子类产生映射配置文件, 所以我们在这应该将

            ContentDocument父类的映射文件ContentResource添加进配置文件。

        © 解决方法

            在配置文件applicationContext-hibernate.xml中手工添加

            <value>org/dudu/model/ContentResource.hbm.xml</value>

3)再次运行DAO测试

        ant test-dao -Dtestcase=ContentFieldDAO

        © 运行报错

            [junit] Testcase:

testGetContentField(org.dudu.dao.ContentFieldDAOTest):

Caused an ERROR

    [junit] Cannot instantiate abstract class or interface:

    org.dudu.model.Page;

 nested exception is org.hibernate.InstantiationException: Cannot

instantiate abstract class or interface: org.dudu.model.Page

            © 错误原因

                ContentFieldlocalizable有引用,localizable加载时会初始化

                它的子类Page,Page是抽象类。

            © 解决方法

                Page抽象类abstract关键字去掉。

 



read-Atleap-9-新闻实体hibernate关系代码分析:【上一篇】
J2ME优化——静态变量与get/set方法比较:【下一篇】
【相关文章】
没有相关文章
【相关评论】
没有相关评论
【发表评论】
姓名:
邮件:
随机码*
评论*
      
|  首 页  |  版权声明  |  联系我们   |  网站地图  |
CopyRight © 2004-2007 软讯网络 All Rigths Reserved.