0

In Eclipselink, when I use @SqlResultSetMappings and I use Query Hint eclipselink.cursor, the console shows me the following exception:

Caused By: java.lang.IllegalArgumentException: Query null, query hint eclipselink.cursor is not valid for this type of query.
at org.eclipse.persistence.internal.jpa.QueryHintsHandler$CursorHint.applyToDatabaseQuery(QueryHintsHandler.java:1640)
at org.eclipse.persistence.internal.jpa.QueryHintsHandler$Hint.apply(QueryHintsHandler.java:367)
at org.eclipse.persistence.internal.jpa.QueryHintsHandler$Hint.apply(QueryHintsHandler.java:345)
at org.eclipse.persistence.internal.jpa.QueryHintsHandler.apply(QueryHintsHandler.java:172)
at org.eclipse.persistence.internal.jpa.QueryImpl.setHintInternal(QueryImpl.java:763)
Truncated. see log file for complete stacktrace

The code is:

@SqlResultSetMapping(
    name = "resultSetMapping",
    entities = @EntityResult(entityClass = Entity.class))

Query q = em.createNativeQuery(sql, "resultSetMapping";
q.setHint(QueryHints.CURSOR, HintValues.TRUE);
q.getSingleResult();

Why cannot I use SqlResultSetMappings with eclipselink.cursor?

Fábio Almeida
  • 276
  • 3
  • 11
  • Cursors aren't supported on the ResultSetMappingQuery that lies underneath native SQL queries. – Chris Jun 22 '17 at 16:07
  • If I use `em.createQuery` with JPQL the error is the same. why? – Fábio Almeida Jun 23 '17 at 13:36
  • The query must return an entity type (select e from Employee e), not raw data like "select e.id from Employee e". – Chris Jun 23 '17 at 17:59
  • But I can do a query like `select a, b.date from EntityA a, (select a.date, a.id.key from EntityB a) b where a.key = 1234 and b.key = a.key`, that will return a List with a Entity and a date. This query can be used with cursor hint. – Fábio Almeida Jun 26 '17 at 11:42
  • I think I found the why. https://www.eclipse.org/forums/index.php?t=msg&th=261203&goto=755536msg_755536 – Fábio Almeida Jun 30 '17 at 12:44
  • When I opened the class QueryHintsHandler, I understood what you said about "Cursors aren't supported on the ResultSetMappingQuery that lies underneath native SQL queries.". Thx for help. – Fábio Almeida Jun 30 '17 at 14:38

0 Answers0