首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

Hibernate继承分页BUG解决办法之一

2012-09-07 
Hibernate继承分页BUG解决方法之一(转载)今天遇到了一个大问题,hibernate的继承分页bug。只要加上分页就不

Hibernate继承分页BUG解决方法之一
(转载)
今天遇到了一个大问题,hibernate的继承分页bug。只要加上分页就不查出结果为0……

有个hibernate警告:

[WARN] firstResult/maxResults specified on polymorphic query; applying in memory!

据说具体原因是hibernate本身的一个bug:参见(人家的劳动成果,不好直接粘过来,大家可以去看看)

http://blog.sina.com.cn/s/blog_4a87727d0100d8dm.html

嘿嘿,上午还愁来着呢,现在已经解决了。

主要就是要注意一下继承时配置文件hbm的配置。

比如说person类和Employee类。Employee继承person。

在java文件中就要在Employee类后面加个extends person。

在配置文件中,不在需要单独为Employee类做hbm映射文件。

<class name="Person">

        <!-- 映射标识属性 -->

        <id name="id" column="person_id">

            <!-- 使用identity的主键生成器策略 -->

            <generator length="80"/>

        <property name="gender"/>

        <!-- 使用union-subclass元素映射Person类的Employee子类 -->

        <union-subclass name="Employee" table="Employee">

            <!-- 映射Employee类的两个普通属性 -->

            <property name="title" not-null="true"/>

            <property name="salary" not-null="true"/>

            <!-- 映射Employee类与Manager类之间的N-1关联 -->

            <many-to-one name="manager" column="manager_id"/>

            <!-- 映射Employee类与Customer类之间的1-N关联 -->

            <set name="customers" inverse="true">

                <key column="employee_id"/>

                <one-to-many table="Employee">

热点排行