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

  • Home
  • SEARCH
  • 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 6986087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:45:51+00:00 2026-05-27T18:45:51+00:00

I have 3 entities inheriting from another entity. I’m using the strategy Single_Table @Inheritance(strategy

  • 0

I have 3 entities inheriting from another entity.
I’m using the strategy Single_Table

@Inheritance(strategy = InheritanceType.SINGLE_TABLE)

E.g. Class B,C and D inherite from A

On entity B I’m loading another entity X eagerly. Unfortunately, Hibernate ignores my annotation and creates a select for each entity B to fetch entity X.

@ManyToOne(fetch=FetchType.EAGER)
private Projekt projekt;

My select statement looks as follows:
´select a from A a´

Some more code examples:

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "DType", discriminatorType = DiscriminatorType.STRING, length = 3)
public abstract class A {}


@Entity
@DiscriminatorValue(B.PREFIX)
public class B extends A {

   @ManyToOne(fetch=FetchType.EAGER)
   private Projekt projekt;
}

Now I expect Hibernate to query all classes which inherite from A, which it does. Unfortunately it also executes a select statement for each result row to query “projekt”, which I want to avoid.

  • 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-27T18:45:51+00:00Added an answer on May 27, 2026 at 6:45 pm

    Hibernate doesn’t insert joins into SQL queries generated from the HQL/JPQL ones for FetchType.EAGER.

    In order to insert join you need to specify left join fetch explicitly, I guess it won’t create problems for InheritanceType.SINGLE_TABLE despite the fact that this relationship doesn’t exists in other subclasses:

    from A a left join fetch a.projekt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two entities: @Entity public class File ....... @Id @GeneratedValue(strategy=GenerationType.AUTO) private int id;
A have two entities. For example timing settings and orders. @Entity public class TimingSettings{
Possibly a dumb question but I have a number of entities all inheriting from
Say I have entities organized in a hierarchy with Parent being the root entity
I have two entities, each from a different database and therefore different edmx files.
I have an Invoice entity and it has child InvoiceLog entities. When I first
I am using Entity Frame work as an ORM and i want to have
I have an application I am working on, using Entity Framework 4.1 as my
I have entities Basket and BasketItem : /** * Acme\BasketBundle\Entity\Basket * * @ORM\Entity(repositoryClass=Acme\BasketBundle\Repository\BasketRepository) *
In hibernate I have entities A and B. There's is a one-to-many from A

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.