mysql查询在两个不同的查询上返回相同的结果

时间:2017-07-04 07:48:56

标签: java mysql spring hibernate

我在Java中编写了一个方法,它根据查询返回列表。我错误地将allotment_date写入了allotmentDate,但是在更正之后它返回相同的列表,并且在mysql表字段中也返回了allotment_date。我不明白为什么allotment_date返回相同的列表。

public List<ShareAllotment> getlis(STUDENT st, Date fromAllotDate, Date toAllotDate, Integer branch_code) {
        Session session = getSessionFactory(st).openSession();
        try {
            Criteria criteria = session.createCriteria(Student.class);
            if (fromAllotDate != null) {
                criteria.add(Restrictions.ge("allotment_date", fromAllotDate));
            }
            if (toAllotDate != null) {
                criteria.add(Restrictions.le("allotment_date", toAllotDate));
            }
            if(branch_code != null && branch_code > 0) 
                criteria.add(Restrictions.eq("branch_code", branch_code));
            return criteria.list();

        } finally {
            session.flush();
            session.close();
        }
    }

public List<ShareAllotment> getlis(STUDENT st, Date fromAllotDate, Date toAllotDate, Integer branch_code) {
        Session session = getSessionFactory(st).openSession();
        try {
            Criteria criteria = session.createCriteria(Student.class);
            if (fromAllotDate != null) {
                criteria.add(Restrictions.ge("allotmentDate", fromAllotDate));
            }
            if (toAllotDate != null) {
                criteria.add(Restrictions.le("allotmentDate", toAllotDate));
            }
            if(branch_code != null && branch_code > 0) 
                criteria.add(Restrictions.eq("branchCode", branch_code));
            return criteria.list();

        } finally {
            session.flush();
            session.close();
        }
    }

学生POGO

@Entity(name = "student")
@Table(name = "student")
public class Student extends BaseDO{

    public Student() {
    }

    @Column(name = "application_date")
    @DateTimeFormat(pattern = "dd-MMM-yyyy")
    @NotNull(message="Please enter Application Date")
    private Date applicationDate;

    @Column(name = "receipt_date")
    @DateTimeFormat(pattern = "dd-MMM-yyyy")
    @NotNull(message="Please enter Date of Receipt")
    private Date dateofReceipt;

    @DateTimeFormat(pattern = "dd-MMM-yyyy")
    @NotNull(message="Please enter Allotment Date")
    @Column(name = "allotment_date")
    private Date allotmentDate;

    @Column(name = "branch_code")
    private Integer branchCode;

    public void setApplicationDate(Date applicationDate) {
        this.applicationDate = applicationDate;
    }

    public Date getAllotmentDate() {
        return allotmentDate;
    }

    @Transient
    public String getAllotmentDateStr() {
        return allotmentDate != null ? Configuration.DATE_FORMAT.format(allotmentDate): "";
    }

    @Transient
    public String getAllotDateShotStr() {
        DateFormat df = new SimpleDateFormat("dd-MMM-yy"); 
        return allotmentDate != null ? df.format(allotmentDate): "";
    }

    public void setAllotmentDate(Date allotmentDate) {
        this.allotmentDate = allotmentDate;
    }

    public Integer getBranchCode() {
        return branchCode;
    }

    public void setBranchCode(Integer branchCode) {
        this.branchCode = branchCode;
    }

}

请帮帮我。提前谢谢。

0 个答案:

没有答案