-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Hibernate 4 JPA - MS SQL Server 2008 R2 - Select Pagination
PostPosted: Mon Jan 30, 2012 1:09 pm 
Newbie

Joined: Tue Oct 05, 2010 10:49 am
Posts: 13
Hello,
I am trying to run a query with pagination on Microsoft SQL Server 2008 R2 with Hibernate 4.
The code is very basic:

Code:
// EntityManager em
int pageSize = 15;
int first = 0;
Query query = em.createQuery("select m from Machine m left join fetch m.platform");
      
query.setMaxResults(pageSize);
query.setFirstResult(first);

@SuppressWarnings("unchecked")
List<Machine> machines = (List<Machine>) query.getResultList();


If the first variable is set to 0, everything is OK, but if I set it to anything other than zero [like 15 for example] hibernate crashes. I tried both the official driver from Microsoft and the jTDS driver. With the jTDS driver I get the following error:
Quote:
java.sql.SQLException: ResultSet may only be accessed in a forward direction.


With the official driver I get the following:
Quote:
The requested operation is not supported on forward only result sets


Cand anybody please give me a hint towards a solution to this problem ? I mean what I want to do is a simple task... just a select with pagination, that's all. I didn't expect it to be so somplicated on MS SQL Server.

My complete configuration:
- Tomcat 7.0.23
- Oracle JDK 6.0.30
- Hibernate 4.0 FINAL
- JPA 2
- Microsoft SQL Server 2008 R2

Thank you in advance!
Matei


Top
 Profile  
 
 Post subject: Re: Hibernate 4 JPA - MS SQL Server 2008 R2 - Select Pagination
PostPosted: Tue Jan 31, 2012 11:30 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
This is actually not a Hibernate issue, it depends exclusively on the JDBC-Driver and the underlying database you are using.
I suggest you to read documentation about about SQLServer cursor types, the jTDS-driver or/and the SQLServerDriver.


Top
 Profile  
 
 Post subject: Re: Hibernate 4 JPA - MS SQL Server 2008 R2 - Select Pagination
PostPosted: Fri Mar 23, 2012 2:45 pm 
Newbie

Joined: Tue Oct 05, 2010 10:49 am
Posts: 13
Problem solved!

Hibernate had been configured to use the org.hibernate.dialect.SQLServerDialect dialect.
I just changed that into org.hibernate.dialect.SQLServer2008Dialect and it worked!


Top
 Profile  
 
 Post subject: Re: Hibernate 4 JPA - MS SQL Server 2008 R2 - Select Pagination
PostPosted: Wed Jun 06, 2012 11:27 pm 
Newbie

Joined: Wed Jun 06, 2012 11:23 pm
Posts: 1
Thanks for the solution..I was experiencing same problem this morning


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.