0
 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.

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.

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.

<!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.

<?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>
Kaushi
  • 198
  • 3
  • 8
  • 20
  • 1
    You haven't stored the marks as strings? – Marko Topolnik Sep 16 '14 at 13:23
  • In the bean, I declared mark as 'String' and in _Database_ I stored mark as 'Varchar2' – Kaushi Sep 16 '14 at 14:07
  • what happens when you do not add the `strStudentMark1 Restrictions`, are you getting the whole list or what. And how do you define your Student Entity, and can you also provide your hibernate configuration as well – dursun Sep 16 '14 at 20:13

1 Answers1

3

Please make sure that the data stored in the Database is an INT. The between will only work with INT Datatype. Also try passing the value as int in code.

MANOJ GOPI
  • 1,279
  • 10
  • 31
  • Yes you are right. When Data type in DB i changed to NUMBER, it worked. But we need to pass String from the application. Anyways Thanks a lot.... – Kaushi Sep 17 '14 at 04:37