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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:13:35+00:00 2026-05-17T17:13:35+00:00

I have a query like below select f.id, s.name, ss.name from first f left

  • 0

I have a query like below

select f.id, s.name, ss.name
from first f
left join second s on f.id = s.id
left join second ss on f.sId = ss.id

If I could use HQL, I would have used HQL constructor syntax to directly populate DTO with the result set.
But, since hibernate doesn’t allow left join without having an association in place I have to use the Native SQL Query.

Currently I am looping through the result set in JDBC style and populating DTO objects.
Is there any simpler way to achieve it?

  • 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-17T17:13:36+00:00Added an answer on May 17, 2026 at 5:13 pm

    You could maybe use a result transformer. Quoting Hibernate 3.2: Transformers for HQL and SQL:

    SQL Transformers

    With native sql returning non-entity
    beans or Map’s is often more useful
    instead of basic Object[]. With
    result transformers that is now
    possible.

    List resultWithAliasedBean = s.createSQLQuery(
      "SELECT st.name as studentName, co.description as courseDescription " +
      "FROM Enrolment e " +
      "INNER JOIN Student st on e.studentId=st.studentId " +
      "INNER JOIN Course co on e.courseCode=co.courseCode")
      .addScalar("studentName")
      .addScalar("courseDescription")
      .setResultTransformer( Transformers.aliasToBean(StudentDTO.class))
      .list();
    
    StudentDTO dto =(StudentDTO) resultWithAliasedBean.get(0);
    

    Tip: the addScalar() calls were
    required on HSQLDB to make it match a
    property name since it returns column
    names in all uppercase (e.g.
    “STUDENTNAME”). This could also be
    solved with a custom transformer that
    search the property names instead of
    using exact match – maybe we should
    provide a fuzzyAliasToBean() method 😉

    References

    • Hibernate Reference Guide
      • 16.1.5. Returning non-managed entities
    • Hibernate’s Blog
      • Hibernate 3.2: Transformers for HQL and SQL
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a query like the one below: SELECT t1.id, t1.Name FROM Table1
I have a query like this: select empno,name from emp where job = 'CLERK'
I have a query like below... SELECT contents.id, contents.title, contents.createdBy, (SELECT userGroup FROM suser_profile
In the most general of cases, I have a query like below: SELECT tutor_school.name,
I have a query like this, SELECT Name FROM Customers WHERE Id IN (1,4,3,6,7)
I have a result from a query like the below, which does not have
I have query like this : SELECT EXTRACT(MONTH FROM d.mydate) AS synmonth, SUM(apcp) AS
I have a query like: SELECT ... FROM ... WHERE .. AND SomeID =
I have a query like so : SELECT * FROM table WHERE premium =
I have a query like this: SELECT COUNT(*) AS amount FROM daily_individual_tracking WHERE sales

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.