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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T14:43:59+00:00 2026-05-10T14:43:59+00:00

@Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) public class Problem { @ManyToOne private Person person; } @Entity

  • 0
@Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) public class Problem {     @ManyToOne     private Person person; }  @Entity @DiscriminatorValue('UP') public class UglyProblem extends Problem {}  @Entity public class Person {     @OneToMany(mappedBy='person')     private List< UglyProblem > problems; } 

I think it is pretty clear what I am trying to do. I expect @ManyToOne person to be inherited by UglyProblem class. But there will be an exception saying something like: ‘There is no such property found in UglyProblem class (mappedBy=’person’)’.

All I found is this. I was not able to find the post by Emmanuel Bernard explaining reasons behind this.


Unfortunately, according to the Hibernate documentation ‘Properties from superclasses not mapped as @MappedSuperclass are ignored.’

Well I think this means that if I have these two classes:

public class A {     private int foo; }  @Entity public class B extens A { } 

then field foo will not be mapped for class B. Which makes sense. But if I have something like this:

@Entity public class Problem {  @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id;  private String name;  public Long getId() {     return id; }  public void setId(Long id) {     this.id = id; }  public String getName() {     return name; }  public void setName(String name) {     this.name = name; } }  @Entity public class UglyProblem extends Problem {  private int levelOfUgliness;  public int getLevelOfUgliness() {     return levelOfUgliness; }  public void setLevelOfUgliness(int levelOfUgliness) {     this.levelOfUgliness = levelOfUgliness; } } 

I expect the class UglyProblem to have fileds id and name and both classes to be mapped using same table. (In fact, this is exactly what happens, I have just checked again). I have got this table:

CREATE TABLE 'problem' (     'DTYPE' varchar(31) NOT NULL,     'id' bigint(20) NOT NULL auto_increment,     'name' varchar(255) default NULL,     'levelOfUgliness' int(11) default NULL,     PRIMARY KEY  ('id') ) AUTO_INCREMENT=2; 

Going back to my question:

I expect @ManyToOne person to be inherited by UglyProblem class.

I expect that because all other mapped fields are inherited and I do not see any reason to make this exception for ManyToOne relationships.


Yeah, I saw that. In fact, I used Read-Only solution for my case. But my question was ‘Why…’ :). I know that there is an explanation given by a member of hibernate team. I was not able to find it and that is why I asked.

I want to find out the motivation of this design decision.

(if you interested how I have faced this problem: I inherited a project built using hibernate 3. It was Jboss 4.0.something + hibernate was already there (you’d download it all together). I was moving this project to Jboss 4.2.2 and I found out that there are inherited mappings of ‘@OneToMany mappedBy’ and it worked fine on old setup…)

  • 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. 2026-05-10T14:43:59+00:00Added an answer on May 10, 2026 at 2:43 pm

    I think it’s a wise decision made by the Hibernate team. They could be less arrogante and make it clear why it was implemented this way, but that’s just how Emmanuel, Chris and Gavin works. 🙂

    Let’s try to understand the problem. I think your concepts are ‘lying’. First you say that many Problems are associated to People. But, then you say that one Person have many UglyProblems (and does not relate to other Problems). Something is wrong with that design.

    Imagine how it’s going to be mapped to the database. You have a single table inheritance, so:

              _____________           |__PROBLEMS__|          |__PEOPLE__|           |id <PK>     |          |          |           |person <FK> | -------->|          |           |problemType |          |_________ |           --------------  

    How is hibernate going to enforce the database to make Problem only relate to People if its problemType is equal UP? That’s a very difficult problem to solve. So, if you want this kind of relation, every subclass must be in it’s own table. That’s what @MappedSuperclass does.

    PS.: Sorry for the ugly drawing 😀

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

Sidebar

Related Questions

I have these 2 classes: @Entity @Table(name = S_MC_CC_CLIENTI) @Inheritance(strategy=InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name=COD_TIPOCLIENTE) @DiscriminatorValue(PF) public class
I have mapped class in JPA. : @Entity @Inheritance(strategy = InheritanceType.JOINED) public class User
@Entity @Inheritance(strategy = InheritanceType.JOINED) public class Foo @Entity @Inheritance(strategy = InheritanceType.JOINED) public class BarFoo
For example, is the following top-level JPA class valid: @Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(
Given the following situation: @Entity @Inheritance(strategy = InheritanceType.JOINED) @Table(name=TOP_TABLE) public class BaseClass implements Serializable
I try to use this mapping : @Entity @Table(name=ecc.\RATE\) @Inheritance(strategy=InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name=DISCRIMINATOR, discriminatorType= DiscriminatorType.STRING) public
I have a Superclass @Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name = entity_type, discriminatorType = DiscriminatorType.STRING)
We have the following classes @Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) // optional annotation as this
Suppose there are three classes: One is: @Entity @Indexed @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name =
@Entity @Table(name=Product_info) public class Product { private int ProductIndex; private int priority; private Date

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.