Showing Hibernate/JPA results in JSF datatable causes: java.lang.NumberFormatException: For input string: "[propertyname]"

Solution 1:

Your Hibernate query is actually returning a List<Object[]>, not a List<Employee> as you incorrectly assumed during the unchecked cast.

Evidence is in the stack trace:

java.lang.NumberFormatException: For input string: "name"
    at java.lang.NumberFormatException.forInputString(Unknown source)
    at java.lang.Integer.parseInt(Unknown source)
    at java.lang.Integer.parseInt(Unknown source)
    at javax.el.ArrayELResolver.toInteger(ArrayELResolver.java:166)
    at javax.el.ArrayELResolver.getValue(ArrayELResolver.java:46)
    ...

The ArrayELResolver is only involved when the base of name (thus, the #{employee}) represents an array like Object[] not a javabean like Bean. EL is attempting to use the name to obtain the array item by index, which can only be an integer like so #{employee[0]} for the 1st item. However, the string value "name" is not parseable as an integer and hence this exception.

You have 2 options to solve this problem:

  • Alter the JSF code to expect a List<Object[]>. Use e.g. #{employee[0]}, #{employee[1]}, etc.

    <p:dataTable var="employee" value="#{bean.employees}">
        <p:column id="name" headerText="Name">
            <h:outputText value="#{employee[0]}" />
        </p:column>
        <p:column id="id" headerText="ID" >
            <h:outputText value="#{employee[1]}" />
        </p:column>
    </p:dataTable>
    
  • Fix the Hibernate query to return a real List<Employee>.

See also:

  • NumberFormatException for input String