Hi this is my entity StudentEntity.java,
@Entity
@NamedQueries({
@NamedQuery(name="totalStudentSQLQuery",
query="select count(*) as MAX_STUDENT from tblstudent"),
@NamedQuery(name="queryForPagination",
query="SELECT s.studentid AS studentid, s.studentname AS studentname, s.contactno AS contactno, s.deptid AS deptid "+
"FROM (SELECT Row_number() OVER() AS row_num, studentid, studentname, contactno, deptid FROM tblstudent order by studentId asc) s" +
" WHERE s.row_num >=:minRow AND s.row_num <=:maxRow")
})
@Table(name="TBLSTUDENT")
public class StudentEntity implements Serializable{
/**
*
*/
private static final long serialVersionUID = 100034222342L;
@Id
@Column(name="STUDENTID")
private Integer studentId;
@Column(name="STUDENTNAME")
private String studentName;
@Column(name="CONTACTNO")
private String contactNumber;
.....
.....
}
I am using Hibernate 4.0 jars for persistence provider, and using JPA ,
My persistense.xml is as follows,
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="forPractise" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/app</jta-data-source>
<class>com.entity.StudentEntity</class>
<class>com.entity.DeptEntity</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.DerbyDialect" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
</properties>
</persistence-unit>
</persistence>
Now when i create a war file of this project and try to deploy in Glassfish server, i get an error
unexpected token: (
org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: ( near line 1, column 116 [SELECT s.studentid AS studentid, s.studentname AS studentname, s.contactno AS contactno, s.deptid AS deptid FROM (SELECT Row_number() OVER() AS row_num, studentid, studentname, contactno, deptid FROM tblstudent order by studentId asc) s WHERE s.row_num >=:minRow AND s.row_num <=:maxRow]
can anybody tell me were i am doing the mistake in the NamedQuery,
I am using Derby database.
If you want to use the classic SQL database dipendent you have to annotate your query with
@NamedNativeQuery.