Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A question aboute EJB-QL

 
Fu Dong Jia
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

(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 ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Me again Can you give a meaningful subject line to your threads ? Naming them all "A question form Sun's Free Proficiency Assessment System" makes it difficult to follow. Thank you
You can edit them by clicking the icon.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic