read-Atleap-8-实做ContentField

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关键字去掉。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值