VoodooChile wrote:
can you post the generated SQL?
Are you using the correct oracle dialect?
If I'm not mistaken, oracle dialect will throw a query around the actual query that will filter the rownum s of the inner query.
SQLGrammarException means (I think) you're using a wrong dialect or your base query is incorrect (or something else causing bad SQL)
Looks that way, although I still can't figure out why adding that one method makes everything fail, especially considering that I copy-pasted the code from an online tutorial.
I changed my code to:
Code:
public List<Employee> getEmployees(int currentPage) {
session = HibernateUtil.getSessionFactory().getCurrentSession();
tx = session.beginTransaction();
Criteria criteria = session.createCriteria(Employee.class)
.addOrder(Order.asc("employeeId"))
.setFirstResult(1)
.setMaxResults(10);
List<Employee> results = criteria.list();
tx.commit();
return results;
}
And here's what appears in the stack trace:
Quote:
java.sql.SQLException: ORA-00923: FROM keyword not found where expected
oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:745) oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
The generated SQL is as follows. It looks like the generated "limit" keyword is what's causing the error:
Quote:
select limit ? ? this_.EMPLOYEE_ID as EMPLOYEE1_0_0_,
this_.MANAGER_ID as MANAGER2_0_0_, this_.FIRST_NAME as FIRST3_0_0_, this_.LAST_NAME
as LAST4_0_0_, this_.EMAIL as EMAIL0_0_, this_.PHONE_NUMBER as PHONE6_0_0_,
this_.HIRE_DATE as HIRE7_0_0_, this_.JOB_ID as JOB8_0_0_, this_.SALARY as SALARY0_0_,
this_.COMMISSION_PCT as COMMISSION10_0_0_, this_.DEPARTMENT_ID as DEPARTMENT11_0_0_ from
EMPLOYEES this_ order by this_.EMPLOYEE_ID asc
The Oracle10g dialect is also correctly specified in my cfg.xml file:
Quote:
<session-factory>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.password">hr</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521/xe</property>
<property name="hibernate.connection.username">hr</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="show_sql">true</property>
<mapping resource="oracle/model/Employee.hbm.xml"/>
</session-factory>