Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1008331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:45:20+00:00 2026-05-16T08:45:20+00:00

I am new to JPA. So my question should be so simple to some.

  • 0

I am new to JPA. So my question should be so simple to some.

Below is the Simple Query in SQL which i would like to convert to JPA. I already have an entity class called TimeEnt.

SELECT 
     SUM(TimeEntryActualHours) as UnBilledHrs,
     SUM (TimeEntryAmount) as UnbilledAmount
FROM TimeEnt WHERE MatterID = 200
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T08:45:21+00:00Added an answer on May 16, 2026 at 8:45 am

    The JPA Query Language does support aggregates functions in the SELECT clause like AVG, COUNT, MAX, MIN, SUM and does support multiple select_expressions in the SELECT clause, in which case the result is a List of Object array (Object[]). From the JPA specification:

    4.8.1 Result Type of the SELECT Clause

    …

    The result type of the SELECT
    clause is defined by the the result
    types of the select_expressions
    contained in it. When multiple
    select_expressions are used in the
    SELECT clause, the result of the query
    is of type Object[], and the
    elements in this result correspond in
    order to the order of their
    specification in the SELECT clause
    and in type to the result types of
    each of the select_expressions
    .

    In other words, the kind of query you mentioned in a comment (and since you didn’t provide your entity, I’ll base my answer on your example) is supported, no problem. Here is a code sample:

    String qlString = "SELECT AVG(x.price), SUM(x.stocks) FROM Magazine x WHERE ...";
    Query q = em.createQuery(qlString);
    Object[] results = (Object[]) q.getSingleResult();
    
    for (Object object : results) {
        System.out.println(object);
    }
    

    References

    • JPA 1.0 Specification
      • 4.8.1 Result Type of the SELECT Clause
      • 4.8.4 Aggregate Functions in the SELECT Clause
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to JPA and have some problems in understanding bidirectional relations. I
I am stuck trying to build the following SQL query in JPA (still new
I have a simple question regarding Entity declaration in JPA. I have an entity
We're using JPA for our new project. We have an inheritance relation which has
I have a question concerning Hibernate 3.6.7 and JPA 2.0. Consider following entities (some
I am new in JPA, so excuse me if my question seems basic. I
I'd like to use JPA over JDBC for a new application. I'm strictly using
I'm new to JPA, so forgive this question if this is pretty standard functionality,
I have a JPA database setup like the following: @Entity public class Contact {
I have a user object represented in JPA which has specific sub-types. Eg, think

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.