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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:45:04+00:00 2026-06-11T17:45:04+00:00

I have a scenario where I have a entity hierarchy structure implemented in hibernate.

  • 0

I have a scenario where I have a entity hierarchy structure implemented in hibernate.
It is InheritanceType.JOINED

Parent class:

@Entity 
@Table(name = "LOY") 
@Inheritance(strategy=InheritanceType.JOINED)
public class Loy implements Serializable 

Child class boundary

@Entity 
@Table(name = "LOY_BOUNDARY") 
@PrimaryKeyJoinColumn(name="ID")
public class LoyBoundary implements Serializable 

Child class percentage

@Entity 
@Table(name = "LOY_PERCENTAGE") 
@PrimaryKeyJoinColumn(name="ID")
public class LoyPercentage implements Serializable 

I have a Customer entity class which is linked to the Loy entity class in a @ManyToOne.
The Customer can only be linked to one Loy at a time.

What I want to achieve is that I want to query the Customer class with unique id (passport number) and then get The Loy for the specific Customer through the @ManyToOne mapping in the Customer entity.

The problem that I’m sitting with is that I do not know which subclass of Loy is linked to the Customer.

  1. I can go instanceOf to get the specific subclass but I want to try and avoid it.
  2. I can also add a visitor pattern in the subclass entity, but not sure if this is best practice.
  • 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-11T17:45:05+00:00Added an answer on June 11, 2026 at 5:45 pm

    I would go with a visitor. Using instanceof won’t work if the ManyToOne is lazy-loaded, because the actual type of the Loy won’t be any of your subclasses, but a Hibernate proxy extending the Loy class. Indeed, Hibernate has no way to know, from the ID of the loy in the customer, which kind of Loy it refers to.

    And a visitor is more OO and cleaner anyway.

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

Sidebar

Related Questions

I have a class hierarchy mapped with InheritanceType.JOINED in Hibernate (3.5.6 final) with JPA
I have some scenario like below : /** * @ORM\Entity * @ORM\Table(name=role) */ class
consider this scenario: I have loaded a Parent entity through hibernate Parent contains a
I have the following scenario (in Java / Hibernate): I have two entity classes:
I have a scenario where I have a base class as one entity, then
I have the following scenario: @Entity class A { @Id @GeneratedValue private long dbId;
I have this scenario well, i'll let the model explain. public class ScheduleMonthlyPerDayModel {
I have the scenario where the data from a single table must be in
I have run into a scenario where Entity Framework 4.0 does not generate an
I have a scenario where a class called Comment references an abstract type called

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.