384 words

setResultClass(cls) - JDO Query's method

void setResultClass(
  Class cls

Specify the type of object in which to return each element of the result of invoking execute or one of its siblings. If the result is not set or set to null, the result class defaults to the candidate class of the query. If the result consists of one expression, the result class defaults to the type of that expression. If the result consists of more than one expression, the result class defaults to Object[]. The result class may be specified to be one of the java.lang classes Character, Boolean, Byte, Short, Integer, Long, Float, Double, String, or Object[]; or one of the java.math classes BigInteger or BigDecimal; or the java.util class Date; or one of the java.sql classes Date, Time, or Timestamp; or a user-defined class.

If there are multiple result expressions, the result class must be able to hold all elements of the result specification or a JDOUserException is thrown.

If there is only one result expression, the result class must be assignable from the type of the result expression or must be able to hold all elements of the result specification. A single value must be able to be coerced into the specified result class (treating wrapper classes as equivalent to their unwrapped primitive types) or by matching. If the result class does not satisfy these conditions, a JDOUserException is thrown.

A constructor of a result class specified in the setResult method will be used if the results specification matches the parameters of the constructor by position and type. If more than one constructor satisfies the requirements, the JDO implementation chooses one of them. If no constructor satisfies the results requirements, or if the result class is specified via the setResultClass method, the following requirements apply:

  • A user-defined result class must have a no-args constructor and one or more public set or put methods or fields.
  • Each result expression must match one of:
    • a public field that matches the name of the result expression and is of the type (treating wrapper types equivalent to primitive types) of the result expression;
    • or if no public field matches the name and type, a public setor if neither of the above applies,a public method must be found with the signature void put(Object, Object). During processing of the results, the first argument is the name of the result expression and the second argument is the value from the query result.
Portable result classes do not invoke any persistence behavior during their no-args constructor or set
cls - the result class
JDO 2.0

This documentation page is derived (with some adjustments) from the JDO 2.2 API
and is available under the terms of the Apache License, v. 2.0.