Getting java.lang.UnsupportedOperationException: query result offset is not supported in EAP7
Issue
java.lang.UnsupportedOperationException: query result offset is not supported
is thrown when calling Hibernates's APIorg.hibernate.query.Query.getResultList()
. What is the root cause of this exception?
18:40:08,258 ERROR [io.undertow.request] (default task-1) UT005023: Exception handling request to /hibernate5-sample/api/books: org.jboss.resteasy.spi.UnhandledException: java.lang.UnsupportedOperationException: query result offset is not supported
...
Caused by: java.lang.UnsupportedOperationException: query result offset is not supported
at org.hibernate.dialect.pagination.TopLimitHandler.processSql(TopLimitHandler.java:56)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2007)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1990)
at org.hibernate.loader.Loader.doQuery(Loader.java:949)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:351)
at org.hibernate.loader.Loader.doList(Loader.java:2787)
at org.hibernate.loader.Loader.doList(Loader.java:2770)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2604)
at org.hibernate.loader.Loader.list(Loader.java:2599)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:505)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:395)
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:220)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1526)
at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1538)
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1506)
at org.hibernate.query.Query.getResultList(Query.java:132)
at com.redhat.cee.hibernatesample.rs.BookResource.getBooks(BookResource.java:43)
at com.redhat.cee.hibernatesample.rs.BookResource$Proxy$_$$_WeldClientProxy.getBooks(Unknown Source)
...
- Database is SQL Server 2019 with
org.hibernate.dialect.SQLServerDialect
for dialect . - The application code looks like the below:
@ApplicationScoped
@Path("/books")
public class BookResource {
@PersistenceContext
EntityManager em;
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<Book> getBooks(@QueryParam("start") int start, @QueryParam("limit") int limit) {
Session session = em.unwrap(Session.class);
String hql = "select b from Book b order by b.id";
Query query = session.createQuery(hql, Book.class);
query.setFirstResult(start);
query.setMaxResults(limit);
List<Book> books = query.getResultList(); // UnsupportedException from this line
return books.stream()
.map(b -> Book.of(b.getId(), b.getTitle(), b.getAuthor()))
.collect(Collectors.toList());
}
}
Environment
- Red Hat JBoss Enterprise Application Platform (EAP)
- 7.3
- Hibernate
- SQL Server 2019
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.