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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:07:47+00:00 2026-05-13T01:07:47+00:00

Today I faced an interesting issue. I’ve been having an inheritance hierarchy with Hibernate

  • 0

Today I faced an interesting issue. I’ve been having an inheritance hierarchy with Hibernate JPA, with SINGLE_TABLE strategy. Later, I added a superclass to the hierarchy, which defined TABLE_PER_CLASS strategy. The result was that the whole hierarchy stared behaving as TABLE_PER_CLASS. This, of course, seems fair, if we read the @Inheriatance javadoc:

Defines the inheritance strategy to be used for an entity class hierarchy. It is specified on the entity class that is the root of the entity class hierarchy.

Hibernate docs, however, say that:

It is possible to use different mapping strategies for different branches of the same inheritance hierarchy

And continues on the exemptions from this statement. This is done via XML configuration.

So, finally, my question is – is there a way (a hibernate property, perhaps) to enable the aforementioned xml behaviour via annotations, and using EntityManager.

  • 1 1 Answer
  • 1 View
  • 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-13T01:07:48+00:00Added an answer on May 13, 2026 at 1:07 am

    Well, if you read the “Inheritance” chapter of Hibernate documentation a little further 🙂 you’ll see that the example given for mixing table-per-hierarchy and table-per-subclass strategies is in reality nothing more than table-per-hierarchy with secondary tables thrown in:

    <class name="Payment" table="PAYMENT">
        <id name="id" type="long" column="PAYMENT_ID">
            <generator class="native"/>
        </id>
        <discriminator column="PAYMENT_TYPE" type="string"/>
        <property name="amount" column="AMOUNT"/>
        ...
        <subclass name="CreditCardPayment" discriminator-value="CREDIT">
            <join table="CREDIT_PAYMENT">
                <property name="creditCardType" column="CCTYPE"/>
                ...
            </join>
        </subclass>
        <subclass name="CashPayment" discriminator-value="CASH">
            ...
        </subclass>
    </class>
    

    You can do the same using @SecondaryTable annotation:

    @Entity
    @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
    @DiscriminatorColumn(name="PAYMENT_TYPE")
    @DiscriminatorValue("PAYMENT")
    public class Payment { ... }
    
    @Entity
    @DiscriminatorValue("CREDIT")
    @SecondaryTable(name="CREDIT_PAYMENT", pkJoinColumns={
        @PrimaryKeyJoinColumn(name="payment_id", referencedColumnName="id")
    )
    public class CreditCardPayment extends Payment { ... }
    
    @Entity
    @DiscriminatorValue("CASH")
    public class CashPayment extends Payment { ... }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I faced an interesting problem today. I have 4 strings which I need to
Today I faced one question in interview. Is it possible to apply inheritance concept
Today I encountered interesting issue. That's what I have: 2 images with humanoids on
Today I faced an interesting thing as FF File API and separate files by
I've faced a really weird behaviour of textarea today. Have been bugfixing it for
Today I faced a strange problem in C#. I have an ASP.NET page where
Today I faced a strange problem. I have an application which is the same
Today I faced the following problem: I registered a new user on my Joobla
Today morning I wake with this weird issue where mongoid was creating a record
Today we faced a quite simple problem that were made even simpler by the

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.