Hi all, I'm having trouble getting setMaxResults to work on an ancient SQL Anywhere database. I've been able to make it work on Sybase 11.9.2/12.5 using the same JDBC driver, but there seems to be some hang up against sql any.
Looking through the code it appears that the Dialect's for both Sybase and SybaseAnywhere do not implement the limit clause (Sybase doesn't have one exaclty, but possible to do with 'set rowcount'). I'm posting all the relevant data below, the thing that stands out to me is the syntax error returned from the jdbc driver says "syntax error near p0" but the SQL generated by hibernate doesn't contain the text "p0".
Thanks in advance for the help in figuring this out, I'm willing to do anything on this end to help the process along.
Brian
Hibernate version: 2.1.6
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="spidermonkey.providers.Provider" table="Providers">
<id name="providerCode" column="ProviderCode">
<generator class="assigned"/>
</id>
<property name="name" column="ProviderName" not-null="true"/>
<property name="lastName" column="LastName" not-null="true"/>
<property name="firstName" column="FirstName"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
String query = "from Provider";
Query q = session.createQuery(query);
q.setMaxResults(10);
List providerList = q.list();
Full stack trace of any exception that occurs:
(in log)
Name and version of the database you are using:
Sybase SQL Anywhere 5.5.03 with OpenServer Gateway. JDBC driver is jConnect 5.5
Debug level Hibernate log excerpt:
2684 [main] DEBUG net.sf.hibernate.impl.SessionImpl - find: from Provider
2687 [main] DEBUG net.sf.hibernate.engine.QueryParameters - named parameters: {}
2706 [main] DEBUG net.sf.hibernate.hql.QueryTranslator - compiling query
2727 [main] DEBUG net.sf.hibernate.impl.SessionImpl - flushing session
2728 [main] DEBUG net.sf.hibernate.impl.SessionImpl - Flushing entities and processing referenced collections
2728 [main] DEBUG net.sf.hibernate.impl.SessionImpl - Processing unreferenced collections
2728 [main] DEBUG net.sf.hibernate.impl.SessionImpl - Scheduling collection removes/(re)creates/updates
2728 [main] DEBUG net.sf.hibernate.impl.SessionImpl - Flushed: 0 insertions, 0 updates, 0 deletions to 0 objects
2728 [main] DEBUG net.sf.hibernate.impl.SessionImpl - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
2728 [main] DEBUG net.sf.hibernate.impl.SessionImpl - Dont need to execute flush
2728 [main] DEBUG net.sf.hibernate.hql.QueryTranslator - HQL: from spidermonkey.providers.Provider
2728 [main] DEBUG net.sf.hibernate.hql.QueryTranslator - SQL: select provider0_.ProviderCode as Provider1_, provider0_.ProviderName as Provider2_, provider0_.LastName as LastName, provider0_.FirstName as FirstName, provider0_.Credentials as Credenti5_, provider0_.LicenseNumber as LicenseN6_ from Providers provider0_
2728 [main] DEBUG net.sf.hibernate.impl.BatcherImpl - about to open: 0 open PreparedStatements, 0 open ResultSets
2728 [main] DEBUG net.sf.hibernate.connection.DriverManagerConnectionProvider - total checked-out connections: 0
2728 [main] DEBUG net.sf.hibernate.connection.DriverManagerConnectionProvider - using pooled JDBC connection, pool size: 0
2732 [main] DEBUG net.sf.hibernate.SQL - select provider0_.ProviderCode as Provider1_, provider0_.ProviderName as Provider2_, provider0_.LastName as LastName, provider0_.FirstName as FirstName, provider0_.Credentials as Credenti5_, provider0_.LicenseNumber as LicenseN6_ from Providers provider0_
2732 [main] DEBUG net.sf.hibernate.impl.BatcherImpl - preparing statement
2737 [main] DEBUG net.sf.hibernate.util.JDBCExceptionReporter - SQL Exception
com.sybase.jdbc2.jdbc.SybSQLException: syntax error near 'p0'
at com.sybase.jdbc2.tds.Tds.processEed(Tds.java:2636)
at com.sybase.jdbc2.tds.Tds.nextResult(Tds.java:1996)
at com.sybase.jdbc2.jdbc.ResultGetter.nextResult(ResultGetter.java:69)
at com.sybase.jdbc2.jdbc.SybStatement.nextResult(SybStatement.java:204) at com.sybase.jdbc2.jdbc.SybStatement.nextResult(SybStatement.java:187) at com.sybase.jdbc2.jdbc.SybStatement.updateLoop(SybStatement.java:1615)
at com.sybase.jdbc2.jdbc.SybStatement.executeUpdate(SybStatement.java:1598)
at com.sybase.jdbc2.jdbc.SybPreparedStatement.executeUpdate(SybPreparedStatement.java:89)
at com.sybase.jdbc2.tds.Tds.adjustMaxRows(Tds.java:2783)
at com.sybase.jdbc2.tds.Tds.language(Tds.java:692)
at com.sybase.jdbc2.jdbc.SybStatement.sendQuery(SybStatement.java:1424) at com.sybase.jdbc2.jdbc.SybPreparedStatement.sendQuery(SybPreparedStatement.java:1025)
at com.sybase.jdbc2.jdbc.SybStatement.executeQuery(SybStatement.java:1494)
at com.sybase.jdbc2.jdbc.SybPreparedStatement.executeQuery(SybPreparedStatement.java:70)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:87)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:875)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:269)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:1033)
at net.sf.hibernate.loader.Loader.list(Loader.java:1024)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1544)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at spidermonkey.providers.ProviderTest.testProvidersLoad(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:289)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:656)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:558)
2738 [main] WARN net.sf.hibernate.util.JDBCExceptionReporter - SQL Error: -131, SQLState: 42W04
2739 [main] ERROR net.sf.hibernate.util.JDBCExceptionReporter - syntax error near 'p0'
2739 [main] DEBUG net.sf.hibernate.impl.BatcherImpl - done closing: 0 open PreparedStatements, 0 open ResultSets
2739 [main] DEBUG net.sf.hibernate.impl.BatcherImpl - closing statement
2742 [main] DEBUG net.sf.hibernate.util.JDBCExceptionReporter - SQL Exception
com.sybase.jdbc2.jdbc.SybSQLException: syntax error near 'p0'
at com.sybase.jdbc2.tds.Tds.processEed(Tds.java:2636)
at com.sybase.jdbc2.tds.Tds.nextResult(Tds.java:1996)
at com.sybase.jdbc2.jdbc.ResultGetter.nextResult(ResultGetter.java:69)
at com.sybase.jdbc2.jdbc.SybStatement.nextResult(SybStatement.java:204) at com.sybase.jdbc2.jdbc.SybStatement.nextResult(SybStatement.java:187) at com.sybase.jdbc2.jdbc.SybStatement.updateLoop(SybStatement.java:1615)
at com.sybase.jdbc2.jdbc.SybStatement.executeUpdate(SybStatement.java:1598)
at com.sybase.jdbc2.jdbc.SybPreparedStatement.executeUpdate(SybPreparedStatement.java:89)
at com.sybase.jdbc2.tds.Tds.adjustMaxRows(Tds.java:2783)
at com.sybase.jdbc2.tds.Tds.language(Tds.java:692)
at com.sybase.jdbc2.jdbc.SybStatement.sendQuery(SybStatement.java:1424) at com.sybase.jdbc2.jdbc.SybPreparedStatement.sendQuery(SybPreparedStatement.java:1025)
at com.sybase.jdbc2.jdbc.SybStatement.executeQuery(SybStatement.java:1494)
at com.sybase.jdbc2.jdbc.SybPreparedStatement.executeQuery(SybPreparedStatement.java:70)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:87)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:875)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:269)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:1033)
at net.sf.hibernate.loader.Loader.list(Loader.java:1024)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1544)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at spidermonkey.providers.ProviderTest.testProvidersLoad(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:289)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:656)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:558)
2744 [main] WARN net.sf.hibernate.util.JDBCExceptionReporter - SQL Error: -131, SQLState: 42W04
2744 [main] ERROR net.sf.hibernate.util.JDBCExceptionReporter - syntax error near 'p0'
2744 [main] ERROR net.sf.hibernate.util.JDBCExceptionReporter - Could not execute query
com.sybase.jdbc2.jdbc.SybSQLException: syntax error near 'p0'
at com.sybase.jdbc2.tds.Tds.processEed(Tds.java:2636)
at com.sybase.jdbc2.tds.Tds.nextResult(Tds.java:1996)
at com.sybase.jdbc2.jdbc.ResultGetter.nextResult(ResultGetter.java:69)
at com.sybase.jdbc2.jdbc.SybStatement.nextResult(SybStatement.java:204) at com.sybase.jdbc2.jdbc.SybStatement.nextResult(SybStatement.java:187) at com.sybase.jdbc2.jdbc.SybStatement.updateLoop(SybStatement.java:1615)
at com.sybase.jdbc2.jdbc.SybStatement.executeUpdate(SybStatement.java:1598)
at com.sybase.jdbc2.jdbc.SybPreparedStatement.executeUpdate(SybPreparedStatement.java:89)
at com.sybase.jdbc2.tds.Tds.adjustMaxRows(Tds.java:2783)
at com.sybase.jdbc2.tds.Tds.language(Tds.java:692)
at com.sybase.jdbc2.jdbc.SybStatement.sendQuery(SybStatement.java:1424) at com.sybase.jdbc2.jdbc.SybPreparedStatement.sendQuery(SybPreparedStatement.java:1025)
at com.sybase.jdbc2.jdbc.SybStatement.executeQuery(SybStatement.java:1494)
at com.sybase.jdbc2.jdbc.SybPreparedStatement.executeQuery(SybPreparedStatement.java:70)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:87)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:875)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:269)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:1033)
at net.sf.hibernate.loader.Loader.list(Loader.java:1024)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1544)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at spidermonkey.providers.ProviderTest.testProvidersLoad(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:289)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:656)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:558)
2754 [Finalizer] DEBUG net.sf.hibernate.impl.SessionImpl - running Session.finalize()
|