| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 717 人关注过本帖
标题:hibernate 多对多分页
只看楼主 加入收藏
huayueouran
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-6-10
结帖率:0
收藏
已结贴  问题点数:0 回复次数:1 
hibernate 多对多分页
每页显示10条记录,中间表条数,就是画面显示条数。如何能以中间表分页呢?
表setting_users和表departments映射关系是多对多,中间表departmenter_rights。
Query query = getSession().createQuery("from DTO");
query.setFirstResult(1);   
query.setMaxResults(10);

查询语句
 Query query = getSession().createQuery("from SettingUsersDTO");
 query.setFirstResult(1);   
 query.setMaxResults(10);
执行结果是setting_users取出10条记录,setting_users(1)中有departments3个。这样画面显示就是12条了。
如何能取出10条呢。也就是说,以中间表分页。

setting_users 表映射
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
    PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.

<hibernate-mapping>
    <class table="setting_users" name="com.helixinsoft.pmgps.dto.SettingUsersDTO">
        <id unsaved-value="0" name="id" type="int" column="id">
            <generator class="sequence">
            </generator>
        </id>
        <property name="names" column="names" unique="false" not-null="true"
            type="string" />
        <property name="passwords" column="passwords" unique="false" not-null="true"
            type="string" />
        <!--property name="company_id" column="company_id" unique="false" not-null="false"
            type="int" /-->
        <property name="rights" column="rights" unique="false" not-null="true"
            type="int" />
        <property name="update_id" column="update_id" unique="false" not-null="true"
            type="int" />
        <property name="update_time" column="update_time" unique="false" not-null="true"
            type="timestamp" />
        <property name="version" column="version" unique="false" not-null="true"
            type="int" />
               
        <!--系统设定用户信息——部门权限-->   
        <set name="departmentsDTOS"
             table="departmenter_rights"
             inverse="false"
             lazy="false" batch-size="10">
            <key column="user_id"/>
            <many-to-many column="department_id" class="com.helixinsoft.pmgps.dto.DepartmentsDTO" lazy="false"/>
        </set>
            
    </class>
</hibernate-mapping>

departments 表映射
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
    PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.

<hibernate-mapping>
    <class table="departments" name="com.helixinsoft.pmgps.dto.DepartmentsDTO">
        <id unsaved-value="0" name="id" type="int" column="id">
            <generator class="native"/>
        </id>
        <!--property name="company_id" column="company_id" unique="false" not-null="true"
            type="int" /-->
        <property name="department_name" column="department_name" unique="false" not-null="false"
            type="string" />
        <property name="start_work_date" column="start_work_date" unique="false" not-null="true"
            type="string" />
        <property name="end_work_date" column="end_work_date" unique="false" not-null="true"
            type="string" />
        <property name="status" column="status" unique="false" not-null="true"
            type="int" />
        <property name="update_id" column="update_id" unique="false" not-null="true"
            type="int" />
        <property name="update_time" column="update_time" unique="false" not-null="true"
            type="timestamp" />
        <property name="version" column="version" unique="false" not-null="true"
            type="int" />
        
        <!--部门信息——系统设定用户信息关联-->
        <set name="settingUsersDTOS"
             table="departmenter_rights"
             inverse="true"
             lazy="false">
            <key column="department_id"/>
            <many-to-many column="user_id" class="com.helixinsoft.pmgps.dto.SettingUsersDTO" lazy="false"/>
        </set>
    </class>
</hibernate-mapping>

搜索更多相关主题的帖子: hibernate 
2011-06-10 10:46
zfish
Rank: 2
等 级:论坛游民
威 望:1
帖 子:23
专家分:20
注 册:2009-3-13
收藏
得分:20 
没必要去对关联字表进行那样的处理,
直接在程序里进行限制一下就行了,或者在jsp中再进行分页也行。
2011-06-14 15:01
快速回复:hibernate 多对多分页
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016097 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved