• Post Reply Bookmark Topic Watch Topic
  • New Topic

Returning multiple values in EJB QL  RSS feed

 
Sunil Singhania
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to return multiple values in my EJB query. The query goes something like this:

SELECT SUM(s.sales) SUM(s.cancels) FROM accounts.

To implement this if I write as below:

Query query = _em.createNamedQuery("Accounts.findAccountData");

Now if I do query.getSingleResult(); how do i retrieve both the values since the ejb finder returns either a single object or a collection?.

Any help is much appreciated


 
Rob Spoor
Sheriff
Posts: 20898
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the result of a query cannot be turned into an object (because it's not an entity and no class / constructor is specified), the result will be an Object[] (a List<Object[]> for multiple results).
 
Sunil Singhania
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many thanks Rob. Yes your answer resolves my query.
 
Rob Spoor
Sheriff
Posts: 20898
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!