0

I am using a nativequery to get the row numbers. However this will return an Object array to me. This gives me a:

SEVERE: Servlet.service() for servlet [Faces Servlet] in context with path [/BowlingInfo] threw exception [For input string: "position"] with root cause
java.lang.NumberFormatException: For input string: "position"

In the case of the normal createQuery it will correctly return "Hallmaster" classes to me and it will execute correctly in my primefaces xhtml.

listHallmastaren = (List<Hallmaster>) em.createNativeQuery("SELECT  id, @rownum := @rownum + 1 AS position, e.name, e.score FROM HALLMASTER e, (SELECT @rownum:=0) t ORDER BY e.score desc").getResultList();
listHallmastaren = em.createQuery("select e from Hallmaster e").getResultList();

To correctly coerse the native query back to the class you expect you need to tell the query to return types of that class. Note the , Hallmaster.class at the end.

listHallmastaren = (List<Hallmaster>) em.createNativeQuery("SELECT  id, @rownum := @rownum + 1 AS position, " +
        " e.name, e.score FROM HALLMASTER e, (SELECT @rownum:=0) t ORDER BY e.score desc", Hallmaster.class).getResultList();
user2130951
  • 2,601
  • 4
  • 31
  • 58
  • Actually that anser is not complete. I have altered the question to include the answer I was looking for. – user2130951 Mar 17 '15 at 08:38
  • You should have altered the question to remove all references/tags related to JSF/PrimeFaces as you're apparently not looking for a JSF/PrimeFaces solution. – BalusC Mar 17 '15 at 08:54

0 Answers0