(quoted from Sun's Free Proficiency Assessment System )
22. Given an excerpt from an entity:
10. @Entity
11. public class Koala {
12. int children;
13. @Id
14. private Integer id;
15. /* ... */
16. }
The following code was written to find the sum and average number of children across all Koala entities (assume the variable em is bound to a valid EntityManager instance):
20. String query = "SELECT SUM(k.children), AVG(k.children) from Koala k";
21. Query q = em.createQuery(query);
22. Object[] res = (Object []) q.getSingleResult();
Which two statements are correct? (Choose two.)
1,If there are no Koala entities in the database, the variable res is set to null after the code exits on line 22.
2,If there are no Koala entities in the database, the variable res contains an array of two null values.
3,If there are no Koala entities in the database, the variable res contains an array holding the values null and 0 respectively.
4,If there are Koala entities, the variable res contains an array with values of type Long and Double, respectively.
5,This code throws a runtime exception.
I think the only correct answer is 2.
If there are Koala entities, the variable res contains an array with values of type Integer and Double.
[ December 11, 2008: Message edited by: Fu Dong Jia ]