首页 新闻 赞助 找找看

hibernate分页查询第二页数据不准确

0
悬赏园豆:20 [已关闭问题] 关闭于 2018-03-01 23:08
问题是,我在查询第一页的时候数据是正常的,set查询四条,结果是五条,第二页查询的时候数据是从第一页的最后一条数据为第二页的第一条数据,查询的记录有8条,已经确实传入的最大页和最小页没问题。 
这是DAO层的代码1

@Override
2 public List<Account> findAll(Account model, PageBean pageBean) { 3 DetachedCriteria detachedCriteria = pageBean.getDetachedCriteria(); 4 String idcardNo=model.getIdcardNo(); 5 String realName = model.getRealName(); 6 String loginName =model.getLoginName(); 7 String status=model.getStatus(); 8 Integer accountId=model.getAccountId(); 9 if (idcardNo != null && idcardNo.length() > 0) { 10 detachedCriteria.add(Restrictions.eq("idcardNo", idcardNo)); 11 12 } 13 if(realName != null && realName.length() > 0) { 14 detachedCriteria.add(Restrictions.eq("realName", realName)); 15 } 16 if(loginName != null && loginName.length() > 0) { 17 detachedCriteria.add(Restrictions.eq("loginName", loginName)); 18 } 19 if(status != null && !status.equals("-1")) { 20 21 detachedCriteria.add(Restrictions.eq("status", status)); 22 } 23 if(accountId != null ) { 24 detachedCriteria.add(Restrictions.eq("idcardNo", idcardNo)); 25 } 26 //从第几条开始 27 int nextMin = pageBean.getPage()*pageBean.getPageSize() + 1; 28 int lastMax = (pageBean.getPage()-1)*pageBean.getPageSize(); 29 detachedCriteria.addOrder(Order.asc("id"));//再加入排序查询 30 List<Account> list =(List<Account>) this.getHibernateTemplate().findByCriteria(detachedCriteria, lastMax, nextMin); 31 32 return list;
这是xml配置
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- 
    Mapping file autogenerated by MyEclipse Persistence Tools
--> 
<hibernate-mapping>
    <class name="com.itheima.NetCTOSS.domain.Account" 
        table="ACCOUNT" schema="SCOTT" >
        <id name="accountId" type="integer">
            <column name="ACCOUNT_ID" precision="9" scale="0" />
            <generator class="seqhilo">
                <param name="sequence">ACCOUNT_SEQ</param>
            </generator>
        </id>

        <property name="recommenderId" type="integer">
            <column name="RECOMMENDER_ID"></column>
        </property>
        <property name="loginName" type="string">
            <column name="LOGIN_NAME" length="30" not-null="true" unique="true" />
        </property>
        <property name="loginPasswd" type="string">
            <column name="LOGIN_PASSWD" length="30" not-null="true" />
        </property>
        <property name="status" type="string">
            <column name="STATUS" length="1" />
        </property>
        <property name="createDate" type="date">
            <column name="CREATE_DATE" length="7" />
        </property>
        <property name="pauseDate" type="date">
            <column name="PAUSE_DATE" length="7" />
        </property>
        <property name="closeDate" type="date">
            <column name="CLOSE_DATE" length="7" />
        </property>
        <property name="realName" type="string">
            <column name="REAL_NAME" length="20" not-null="true" />
        </property>
        <property name="idcardNo" type="string">
            <column name="IDCARD_NO" length="18" not-null="true" unique="true" />
        </property>
        <property name="birthdate" type="date">
            <column name="BIRTHDATE" length="7" />
        </property>
        <property name="gender" type="string">
            <column name="GENDER" length="1" />
        </property>
        <property name="occupation" type="string">
            <column name="OCCUPATION" length="50" />
        </property>
        <property name="telephone" type="string">
            <column name="TELEPHONE" length="15" not-null="true" />
        </property>
        <property name="email" type="string">
            <column name="EMAIL" length="50" />
        </property>
        <property name="mailaddress" type="string">
            <column name="MAILADDRESS" length="50" />
        </property>
        <property name="zipcode" type="string">
            <column name="ZIPCODE" length="6" />
        </property>
        <property name="qq" type="string">
            <column name="QQ" length="15" />
        </property>
        <property name="lastLoginTime" type="date">
            <column name="LAST_LOGIN_TIME" length="7" />
        </property>
        <property name="lastLoginIp" type="string">
            <column name="LAST_LOGIN_IP" length="15" />
        </property>
      
        <set name="services" inverse="true" cascade="all" lazy="true" >
            <key column="account_id"></key>
            <one-to-many class="com.itheima.NetCTOSS.domain.Service"/>
        </set>
      
    </class>
</hibernate-mapping>

这是实体类

package com.itheima.NetCTOSS.domain;



import java.util.Date;
import java.util.HashSet;
import java.util.Set;



/**
 * Account entity. @author MyEclipse Persistence Tools
 */

public class Account implements java.io.Serializable {

    // Fields

    private Integer accountId;
    private Integer recommenderId;//推荐人的id
    private String loginName;
    private String loginPasswd;
    private String status;
    private Date createDate;
    private Date pauseDate;
    private Date closeDate;
    private String realName;
    private String idcardNo;
    private Date birthdate;
    private String gender;
    private String occupation;
    private String telephone;
    private String email;
    private String mailaddress;
    private String zipcode;
    private String qq;
    private Date lastLoginTime;
    private String lastLoginIp;
    //追加属性,用于存储相关的Service记录
    private Set<Service> services = new HashSet<Service>();

    public Set<Service> getServices() {
        return services;
    }

    public void setServices(Set<Service> services) {
        this.services = services;
    }

    // Property accessors
    public Integer getRecommenderId() {
        return recommenderId;
    }

    public void setRecommenderId(Integer recommenderId) {
        this.recommenderId = recommenderId;
    }



    public Integer getAccountId() {
        return accountId;
    }

    public void setAccountId(Integer accountId) {
        this.accountId = accountId;
    }

    public String getLoginName() {
        return this.loginName;
    }

    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }

    public String getLoginPasswd() {
        return this.loginPasswd;
    }

    public void setLoginPasswd(String loginPasswd) {
        this.loginPasswd = loginPasswd;
    }

    public String getStatus() {
        return this.status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public Date getCreateDate() {
        return this.createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public Date getPauseDate() {
        return this.pauseDate;
    }

    public void setPauseDate(Date pauseDate) {
        this.pauseDate = pauseDate;
    }

    public Date getCloseDate() {
        return this.closeDate;
    }

    public void setCloseDate(Date closeDate) {
        this.closeDate = closeDate;
    }

    public String getRealName() {
        return this.realName;
    }

    public void setRealName(String realName) {
        this.realName = realName;
    }

    public String getIdcardNo() {
        return this.idcardNo;
    }

    public void setIdcardNo(String idcardNo) {
        this.idcardNo = idcardNo;
    }

    public Date getBirthdate() {
        return this.birthdate;
    }

    public void setBirthdate(Date birthdate) {
        this.birthdate = birthdate;
    }

    public String getGender() {
        return this.gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getOccupation() {
        return this.occupation;
    }

    public void setOccupation(String occupation) {
        this.occupation = occupation;
    }

    public String getTelephone() {
        return this.telephone;
    }

    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }

    public String getEmail() {
        return this.email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getMailaddress() {
        return this.mailaddress;
    }

    public void setMailaddress(String mailaddress) {
        this.mailaddress = mailaddress;
    }

    public String getZipcode() {
        return this.zipcode;
    }

    public void setZipcode(String zipcode) {
        this.zipcode = zipcode;
    }

    public String getQq() {
        return this.qq;
    }

    public void setQq(String qq) {
        this.qq = qq;
    }

    public Date getLastLoginTime() {
        return this.lastLoginTime;
    }

    public void setLastLoginTime(Date lastLoginTime) {
        this.lastLoginTime = lastLoginTime;
    }

    public String getLastLoginIp() {
        return this.lastLoginIp;
    }

    public void setLastLoginIp(String lastLoginIp) {
        this.lastLoginIp = lastLoginIp;
    }

}

 

问题补充:

用的是oracle

易翔的主页 易翔 | 初学一级 | 园豆:185
提问于:2018-02-28 22:19
< >
分享
所有回答(2)
0

findByCriteria这个方法没有贴出来

番茄先生 | 园豆:911 (小虾三级) | 2018-03-01 10:19

这个是hibernate的API

支持(0) 反对(0) 易翔 | 园豆:185 (初学一级) | 2018-03-01 10:23

@易翔: ssh框架了解的少,不好意思,基本都是ssm的架构,这个api如果有源码的话跟一下debug看一下

支持(0) 反对(0) 番茄先生 | 园豆:911 (小虾三级) | 2018-03-01 10:42
0

我自己逻辑错了hibernate的分页查询参数是第几条开始查询,每页显示几条,而我传进去的参数是最大页和最小页,所以导致数据错误,现在改过来可以正常显示了,

易翔 | 园豆:185 (初学一级) | 2018-03-01 23:06
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册