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.sourceforge.net/hibernate-mapping-3.0.dtd">
<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.sourceforge.net/hibernate-mapping-3.0.dtd">
<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
----------------解决方案--------------------------------------------------------
没必要去对关联字表进行那样的处理,
直接在程序里进行限制一下就行了,或者在jsp中再进行分页也行。
----------------解决方案--------------------------------------------------------