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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:20:10+00:00 2026-06-04T18:20:10+00:00

I have tree of classes: classA { classB b; classC c; ….. } I

  • 0

I have tree of classes:

classA {  
      classB b;  
      classC c;
      .....
} 

I have HQL query like this:

SELECT a.field1, b.field2, c.field3, c.field4
FROM a LEFT OUTER JOIN b ON a.id = b.fk
       LEFT OUTER JOIN c ON b.id = c.fk 

This query returns List<Object[]>.

Is it possible to cast the returned data to the following class:

classD {
    Type1 fiedl1;
    Type2 field2;
    Type3 field3;
}

So can casting be made by Hibernate or I need manually do all casting?

  • 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-04T18:20:13+00:00Added an answer on June 4, 2026 at 6:20 pm

    There are different types of selects in JPA queries. You are currently using Array as a return type, what you need is Construct return type. Here is how to achieve this:

    String queryStr =
        "select NEW package.YourDefinedCustomClass(
         a.field1, b.field2, c.field3, c.field4) from a left outer join b 
         on a.id=b.fk left outer join c on b.id=c.fk";
    
    TypedQuery<YourDefinedCustomClass> query =
        em.createQuery(queryStr, YourDefinedCustomClass.class);
    
    List<YourDefinedCustomClass> results = query.getResultList();
    

    Basically there are two things:

    1. Custom class must be your results return type
    2. Custom class must have a constructor which takes result values you define in query string.

    Read more on selects in JPA2 queries.

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

Sidebar

Related Questions

Lets say i have something like this: This is file tree.py: class leaf(): def
I have a tree-like structure of abstract classes and case classes representing an Abstract
I have a tree view representing certain items. This tree is always two levels
I have a tree panel and I would like to associate an action to
I have some ontology (campus.owl). There are tree classes (Student, Sport, Lecturer). Student class
So, I'd like to hear what you all think about this. I have a
I am assigning protocols in a couple classes that follow an inheritance tree. Like
I am using Ruby on Rails 3.0.7 and I have tree classes what behavior
I have such case classes: abstract class Tree case class Sum(l: Tree, r: Tree)
I am using EXTJS4. I have a tree which displays classes (classname) on one

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.