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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:22:07+00:00 2026-06-01T04:22:07+00:00

I have a complex JPA/Hibernate problem. I have two entities A and B. A

  • 0

I have a complex JPA/Hibernate problem.
I have two entities A and B. A references B, but this relationship is not required.

public class A {

@JoinColumn(name = "b_id", referencedColumnName = "b_id")
@OneToOne
private B b;

}

I write SELECT NEW dto(a.b) FROM A a this generates inner join, which isn’t good for me, because a.b can be null and I want all of the A entites. So I rewrite my query like this: SELECT NEW dto(b) FROM A a LEFT JOIN B b We have to use alias (b) to prevent inner join and get only the outer join. Ok I get all line, but I get extra queries, Hibernate generates SELECT queries for all of B entities. Why, how can I stop this, I use left join, because I want only one query.

Edit:

The same problem with inner joins. If use SELECT NEW dto(a.b) FROM A a additional SELECT b FROM B b WHERE b.id = ? occures, but if I call SELECT NEW dto(a.b.id) FROM A a there isn’t additional select for B entites.

Edit2:

This is exactly same as my problem: Same problem, without possible solution.

Because I don’t load the parent object itself, Hibernate doesn’t load eagerly B…

  • 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-01T04:22:09+00:00Added an answer on June 1, 2026 at 4:22 am

    Now I know what was caused the problem, and I also know the solution.

    The partially solution is to use hibernate’s setResultTransformer method. Unfortunatelly JPA doesn’t support it…

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

Sidebar

Related Questions

I have a complex MySQL problem. SELECT * FROM banners, content_id_country, languages WHERE content_id_country.content_id
I have a complex sorting problem with my SQL statement. I have a table
I have complex logic which is not possible (too slow) to run through PHP
We are using Hibernate as persistency layer and have complex object model. Without exposing
I have a JPA entity class with a composite primary key (uid,lid) that in
I have complex logical expression that look like this: ((((!((cond1) || (cond2) || (cond3))
I have two CAShapeLayers insde the main layer of UIView. The CAShapeLayers have complex
I have complex data structure, like this: OrderedHash, keys are dates and values are
I have complex model with double values...I have problem with pass them into object.
I have been reporting with jasperreports and JPA, all this reports are just catalogs

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.