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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:31:05+00:00 2026-05-14T08:31:05+00:00

I am experimenting with Hibernate to gain experience. I created a class Person with

  • 0

I am experimenting with Hibernate to gain experience. I created a class Person with two subclasses: Student and Worker:

public abstract class Person {
    private Long id;
    ...
}

public class Student extends Person { ... }

Another class, Employer, has a bidirectional one-to-many relationship with Worker.

public class Worker extends Person {
    private Employer employer;
    ...
}

public class Employer {
    private String taxId;
    private Set<Worker> employees = new HashSet<Worker>();
    ...
}

for which the mapping is

<class name="Employer" table="EMPLOYER">
    <id name="taxId" column="TAX_ID" length="11">
        <generator class="assigned"/>
    </id>
    ...
    <set name="employees" inverse="true">
        <key column="EMPLOYER_TAX_ID"/>
        <one-to-many class="Worker"/>
    </set>
</class>

The inheritance hierarchy is modelled with a mixed strategy, where Student is mapped to the PERSON table, but Worker is stored in its own table, joined with a foreign key:

<class name="Person" table="PERSON">
    <id name="id" column="PERSON_ID" type="long" unsaved-value="0">
        <generator class="native"/>
    </id>
    <discriminator column="PERSON_TYPE" type="string"/>
    ...
    <subclass name="Student" discriminator-value="STU"> ... </subclass>

    <subclass name="Worker" discriminator-value="WRK">
        <join table="WORKER">
            <key column="WORKER_ID"/>
            <many-to-one name="employer" column="EMPLOYER_TAX_ID" cascade="save-update"/>
            ...
        </join>
    </subclass>
</class>

I use Apache Derby 10.5.3.0 and autogenerate the schema by setting hibernate.hbm2ddl.auto to create-drop.

To test all this, I created a DBUnit test with the following dataset:

<EMPLOYER   TAX_ID          = "1234567890"
            ...
/>
<PERSON   PERSON_ID         = "12345"
          PERSON_TYPE       = "WRK"
          ...
/>
<WORKER   WORKER_ID         = "12345"
          EMPLOYER_TAX_ID   = "1234567890"
          ...
/>

I have a test which loads the worker entity and verifies that it has the correct employee. This passes. Then a test for the opposite direction:

    String taxId = "1234567890";

    Employer employer = (Employer) session.get(Employer.class, taxId);

    assertNotNull(employer);
    assertThat(employer.getEmployees().size(), is(1));

Upon execution, the last assert fails because the set of employees is empty.

Digging deeper, I found that for some reason Hibernate looks for (and creates) the EMPLOYER_TAX_ID column in table PERSON instead of WORKER! It is also present in WORKER, but that one is not used in the query. The select statements for populating the set of employees is:

select
    employees0_.EMPLOYER_TAX_ID as EMPLOYER10_1_,
    employees0_.PERSON_ID as PERSON1_1_,
    employees0_.PERSON_ID as PERSON1_1_0_,
    employees0_.FIRST_NAME as FIRST3_1_0_,
    employees0_.FAMILY_NAME as FAMILY4_1_0_,
    employees0_.DATE_OF_BIRTH as DATE5_1_0_,
    employees0_.HOME_ADDRESS as HOME6_1_0_,
    employees0_.CITY as CITY1_0_,
    employees0_.ZIP as ZIP1_0_,
    employees0_1_.EMPLOYER_TAX_ID as EMPLOYER2_2_0_,
    employees0_1_.JOB_TITLE as JOB3_2_0_,
    employees0_1_.JOB_GRADE as JOB4_2_0_,
    employees0_1_.START_DATE as START5_2_0_ 
from
    PERSON employees0_ 
inner join
    WORKER employees0_1_ 
        on employees0_.PERSON_ID=employees0_1_.WORKER_ID 
where
    employees0_.EMPLOYER_TAX_ID=?

Why is this? And how can I make Hibernate find EMPLOYER_TAX_ID in the WORKER table?

Note that since this is an experimental project, I can change just about anything. I appreciate any workarounds, but I would prefer understanding what’s going on and fixing this mapping as it is (as much as possible).

Update: if I switch to a clean <joined-subclass> inheritance mapping strategy, the generated schema looks as it should and the test passes. This is a good enough workaround, but I am still curious whether there is a way to make the mixed strategy work properly.

  • 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-14T08:31:06+00:00Added an answer on May 14, 2026 at 8:31 am

    This sounds like known bug: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1015

    It is known since ages and has been reported tons of times. Still, they are not fixing it…

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

Sidebar

Related Questions

I'm just experimenting with Optimistic locking. I have the following class: @Entity public class
I am experimenting with Dart. I have created an on click event like so:
i am experimenting using Hibernate. I am trying to get a User by id
I am experimenting with JPA in standalone mode (backed by Hibernate). I've noticed that
I've been experimenting with hibernate and spring and servlets. Now, I'm stuck. Why am
Recently I've been experimenting with the use of the Func<T> class, and so far
Experimenting with Swing, I learnt that there are two ways of using JOptionPane and
Experimenting with the TcpClient and TcpListener class and for some reason when I have
I am experimenting with NHibernate (version 2.1.0.4000) with Fluent NHibernate Automapping. My test set
Experimenting with Scala... I'm trying to define something analogous to the @ hack in

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.