简体   繁体   English

休眠-()之间的限制

[英]Hibernate - Restriction between()

 Criteria cr=session.createCriteria(Student.class).add(Restrictions.between("strStudentMark1", "90", "100"));

In the above code snippet, I have given the mark between 90 and 100. In the Student table, there are fields between marks 90 and 100. but am not getting those in the output. 在上面的代码片段中,我给了90到100之间的标记。在Student表中,标记90到100之间有字段。但是没有在输出中得到这些字段。

What could be the problem? 可能是什么问题呢? Am I making any mistake? 我有什么错误吗?

EDIT 编辑

Yes am getting the whole list when I run. 是的,我跑步时会得到全部清单。

Criteria cr=session.createCriteria(Student.class);

Student entity is below with generated Getters and Setters. 下面是带有生成的Getter和Setter的学生实体。

import java.io.Serializable;

public class Student implements Serializable {

private String strStudentID;
private String strStudentRegNO;
private String strStudentName;
private String strStudentMark1;
private String strStudentMark2;
private String strStudentDegree;
private String strStudentMobileNO;
private String strStudentMailID;
private String strSalary;


public String getStrSalary() {
    return strSalary;
}
public void setStrSalary(String strSalary) {
    this.strSalary = strSalary;
}
public String getStrStudentID() {
    return strStudentID;
}
public void setStrStudentID(String strStudentID) {
    this.strStudentID = strStudentID;
}
public String getStrStudentRegNO() {
    return strStudentRegNO;
}
public void setStrStudentRegNO(String strStudentRegNO) {
    this.strStudentRegNO = strStudentRegNO;
}
public String getStrStudentName() {
    return strStudentName;
}
public void setStrStudentName(String strStudentName) {
    this.strStudentName = strStudentName;
}
public String getStrStudentMark1() {
    return strStudentMark1;
}
public void setStrStudentMark1(String strStudentMark1) {
    this.strStudentMark1 = strStudentMark1;
}
public String getStrStudentMark2() {
    return strStudentMark2;
}
public void setStrStudentMark2(String strStudentMark2) {
    this.strStudentMark2 = strStudentMark2;
}
public String getStrStudentDegree() {
    return strStudentDegree;
}
public void setStrStudentDegree(String strStudentDegree) {
    this.strStudentDegree = strStudentDegree;
}
public String getStrStudentMobileNO() {
    return strStudentMobileNO;
}
public void setStrStudentMobileNO(String strStudentMobileNO) {
    this.strStudentMobileNO = strStudentMobileNO;
}
public String getStrStudentMailID() {
    return strStudentMailID;
}
public void setStrStudentMailID(String strStudentMailID) {
    this.strStudentMailID = strStudentMailID;
}


}

hibernate.cfg.xml. hibernate.cfg.xml。

<!DOCTYPE hibernate-configuration PUBLIC 
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>

    <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
    <property name="connection.url">jdbc:oracle:thin:@aaaa:bbbb</property>
    <property name="connection.username">xxx</property>
    <property name="connection.password">yyy</property>
    <!-- <property name="connection.pool_size">5</property> -->

       <!-- SQL dialect -->
    <property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
        <!-- Echo all executed SQL to stdout -->

    <property name="show_sql">true</property>
    <property name="current_session_context_class">thread</property>

    <!-- <property name="hbm2ddl.auto">update</property> -->

    <mapping resource="com/hibresources/Student.hbm.xml"/>
</session-factory>
</hibernate-configuration>

Student.hbm.xml. Student.hbm.xml。

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 17 Dec, 2010 5:54:42 AM by Hibernate Tools 3.3.0.GA -->
<hibernate-mapping>
<class name="com.bean.Student" table="STUDENT">
    <meta attribute="class-description">
        This class has details abt Students
    </meta>
    <id name="strStudentID" >
        <column name="STUID" />
    </id>
    <property name="strStudentRegNO"  >
        <column name="STUREG_NO" />
    </property>
    <property name="strStudentName" >
        <column name="STUNAME" />
    </property>
    <property name="strStudentMark1" >
        <column name="STUMARK1" />
    </property>

    <property name="strStudentMark2" >
        <column name="STUMARK2" />
    </property>
    <property name="strStudentDegree" >
        <column name="DEGREE" />
    </property>

    <property name="strStudentMobileNO" >
        <column name="MOBILENO" />
    </property>

    <property name="strStudentMailID" >
        <column name="MAILID" />
    </property>

    <property name="strSalary" >
        <column name="SALARY" />
    </property>

</class>
</hibernate-mapping>

Please make sure that the data stored in the Database is an INT. 请确保存储在数据库中的数据为INT。 The between will only work with INT Datatype. 两者之间仅适用于INT数据类型。 Also try passing the value as int in code. 还可以尝试在代码中将值作为int传递。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM