jpa - Hibernate/JDBC generates wrong SQL for Informix database -


i'm trying implement pagination in our spring application using standard jpa methods. here's simplified example:

typedquery<department> depsquery = em.createquery("select d department d", department.class); depsquery.setfirstresult(20); depsquery.setmaxresults(10); depsquery.getresultlist(); 

this query should generate select skip 20 first 10 in informix. however, generates this:

select first 30 department0_.id ... department department0_ 

i have <driver-class>com.informix.jdbc.ifxdriver</driver-class> in standalone.xml of jboss , <property name="hibernate.dialect" value="org.hibernate.dialect.informixdialect" /> in persistence.xml file. how can make hibernate/jdbc produce right query?

the "org.hibernate.dialect.informixdialect" doesn't support limit. here snippet class:

public boolean supportslimitoffset() {         return false;     }      public string getlimitstring(string queryselect, int offset, int limit) {         if ( offset > 0 ) {             throw new unsupportedoperationexception( "query result offset not supported" );         }         return new stringbuffer( queryselect.length() + 8 )                 .append( queryselect )                 .insert( queryselect.tolowercase().indexof( "select" ) + 6, " first " + limit )                 .tostring();     } 

you extend class create custom dialect. override both of above methods.

public boolean supportslimitoffset() {     return true; }  public string getlimitstring(string queryselect, int offset, int limit) {     return new stringbuffer( queryselect.length() + 8 )             .append( queryselect )             .insert( queryselect.tolowercase().indexof( "select" ) + 6," skip " + offset + " first " + limit).tostring(); } 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -