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 8172863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:55:10+00:00 2026-06-06T21:55:10+00:00

Until now I selected Entities like this: public List<Customer> findAll() { TypedQuery<Customer> query =

  • 0

Until now I selected Entities like this:

 public List<Customer> findAll()
 {
     TypedQuery<Customer> query = getEntityManager().createNamedQuery(Customer.FindAll, Customer.class);

     return query.getResultList();
 }

This works. And with method invocation of those Entities from the result set, I can even get the data from “joined” tables, so I never need to make a “real” join in JPQL. (This is what JPA is about).

Now I’d like to get a list of customers with their turnover within a given period, let’s say January 2011 until June 2012. A native query will look like this:

select cus_customer_code, cus_last_name, sum(trn_total_turnover_euro) 
from customer, transaction 
where t2c_cus_id = cus_id 
and date_part('month', trn_date) between 1 and 6 
and date_part('year', trn_date) between 2011 and 2012
group by cus_customer_code, cus_last_name;

This query works in database. But how can I do this in JPQL and what would be the result of this statement, a list of a pair of 2 Entities or something like that? Or is this not possible in this way in JPQL, so do I have to use native queries instead?

  • 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-06-06T21:55:11+00:00Added an answer on June 6, 2026 at 9:55 pm

    Create an additional class with members you want. In this example, org.test.MyClass.

    public MyClass {
        private String message;
        private Int time;
    
        public MyClass ( String msg, Int time ) { ... }
    
        // get / set
    }
    

    Then use the

    List<MyClass> list = em.createQuery("SELECT NEW org.test.MyClass( 'Foo', 123 ) FROM IrcEvent ev", MyClass.class).getResultList();
    

    Or, for scalar values:

    List<Object[]> list = em.createQuery("SELECT 'Foo', 123 FROM IrcEvent ev", Object[].class).getResultList();
    

    Hibernate didn’t implement scalars properly until recently:
    https://hibernate.onjira.com/browse/HHH-6591
    https://hibernate.onjira.com/browse/HHH-6695

    Here’s a nice article about SELECTs in general:
    http://www.objectdb.com/java/jpa/query/jpql/select

    Hibernate manual has it covered quite briefly: http://docs.jboss.org/hibernate/orm/4.1/manual/en-US/html_single/#queryhql-select

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a dialog box and using the (this) isnt working. Up until now
Until now I've always used the ASP.NET MVC framework source for debugging ASP.NET MVC.
Until now I've been only writing console applications but I need to write a
Until now I was logging the Error message and the stack trace of an
Until now I've been used to using DAOs to retrieve information from databases. Other
Until now, I was debugging my PHP scripts and testcases using vim and the
Up until now we used Ant in my company. Whenever we wanted to send
Up until now I used DateTime.Now for getting timestamps, but I noticed that if
Up until now, I have maintained a 'dictionary' table in my database, for example:
Up until now I just put all my jQuery goodness inside the $(document).ready() function,

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.