Hi, Program is not able to recognize Named query put in hbm file. Below is my HBM file
Student.hbm.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" > <hibernate-mapping> <class name="edu.model.Student" table="STUDENT"> <id name="studentNo" column="STUDENTNO"> <generator class="sequence" /> </id> <property name="studentName" column="SNAME"/> <query name = "HQLStudent1" > <![CDATA[select student.studentNo, student.studentName from Student student where student.studentNo >:studentNo]]> </query> </class> </hibernate-mapping>
Below is Hibernate Config file
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property> <property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:SURESH</property> <property name="hibernate.connection.username">scott</property> <property name="hibernate.connection.password">tiger</property> <property name="dialect">org.hibernate.dialect.Oracle9Dialect</property> <property name="hibernate.show_sql">true</property> <property name="hibernate.hbm2ddl.auto">update</property> <property name="hibernate.use_sql_comments">true</property> <mapping resource="edu/mapping/Student.hbm.xml" /> <mapping resource="edu/mapping/Employee.hbm.xml" /> </session-factory> </hibernate-configuration>
Below is my Java file
public static void main(String[] args) { Session session = SessionUtil.currentSession(); Query query = session.getNamedQuery("HQLStudent1"); query.setLong("studentNo",new Long(1)); List stuList = query.list(); Iterator iterator = stuList.iterator(); while(iterator.hasNext()){ Student student = (Student)iterator.next(); System.out.println(student); } }
}
Pls, help
|