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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:16:57+00:00 2026-06-04T14:16:57+00:00

This is the scenario: I have 2 classes mapped with hibernate: "Foo" and "EnhancedFoo"

  • 0

This is the scenario:

  • I have 2 classes mapped with hibernate: "Foo" and "EnhancedFoo"

  • both classes are mapped to the same table "foo"

  • EnhancedFoo extends Foo

  • Foo.hbm.xml contains a named query "find active foos" which goes like this:

     from Foo foo where foo.active = true
    

Now, if I try to load the configuration I get this exception:

could not resolve property: active of: EnhancedFoo [
    from EnhancedFoo foo where foo.active = true
]

which is kind of correct since in EnhancedFoo.hbm.xml there isn’t a mapped property "active", but then why is hibernate replacing "Foo" with "EnhancedFoo"?


This is what I’ve tried:

tried to add a "enity-name" attribute on the mapping files like so:

<class name="myproject.data.entity.Foo" table="foo" entity-name="Foo">
.......
<class name="myproject.data.entity.EnhancedFoo" table="foo" entity-name="EnhancedFoo">

and then configuration loads fine, but whenever I try to insert a Foo I get this:

org.hibernate.MappingException: Unknown entity: myproject.data.entity.Foo

These are the relevant parts of code:

//Foo.java
public class Foo 
{
  private long id;
  private boolean active;

  // getters and setters
}


//EnhancedFoo.java
public class EnhancedFoo extends Foo
{
  private String extraProperty

  // getter and setter
}

//Foo.hbm.xml
//.....
<class name="myproject.data.entity.Foo" table="foo" entity-name="Foo">
  <id column="id" name="id">
    <generator class="assigned"/>
  </id>

  <property name="active" column="active" />
</class>

<query name="find_active_foos">
  <![CDATA[
    from Foo foo where foo.active = true
  ]]>
</query>


//EnhancedFoo.hbm.xml
//.....
<class name="myproject.data.entity.EnhancedFoo" table="foo" entity-name="EnhancedFoo">
  <id column="id" name="id">
    <generator class="assigned"/>
  </id>
</class>
  • 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-04T14:16:58+00:00Added an answer on June 4, 2026 at 2:16 pm

    I see two problems:

    1) You never should both map a superclass and a subclass. The problem is, the subclass instance also is an instance of the superclass, in your example an EnhancedFoo instance also is an instance of Foo. This confuses hibernate when looking in the session cache. (I didn’t have your problem, but I had the effect, when I loaded the superclass instance with the primary key value as the condition then uniqueResult() failed, because it found in the cache one instance of the superclass and one of the subclass.) Your replaced Foo also might be caused be a similar effect.

    If you want to continue with the two mappings, you can do like this

    //AbstractFoo.java
    public abstract class AbstractFoo 
    {
      private long id;
      private boolean active;
      // getters and setters
    }
    
    //Foo.java
    public class Foo extends AbstractFoo
    {  // empty body
    }
    
    //EnhancedFoo.java
    public class EnhancedFoo extends AbstractFoo
    {
      private String extraProperty
      // getter and setter
    }
    

    and you let the mapping files as they are.

    (An other possibility is to map only one class and handle the differences in Java.)

    2) For your insert problem:
    You got the error message Unknown entity: myproyect.data.entity.Foo with ‘y’ instead of ‘j’ in project. Do you have a typo anywhere there?

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

Sidebar

Related Questions

I have this scenario. I have a form A and form B . both
This is the scenario: I have nested classes and need to serialize then in
I have the following scenario (in Java / Hibernate): I have two entity classes:
Imagine this scenario: You have a desktop and a laptop. The desktop has a
Please Consider this scenario: We have a base class called clsMain : class clsMain
In my android app I have this scenario - I have a Gallery where
I have this scenario: WServer 2008, SQL Server 2005, MS Analysis services (SSAS), ISS7
I have this scenario in my 3-tier app with a Service Layer that serves
I have this scenario. I want group on Country and Category. A store can
I have this scenario where I would like to redirect my domains using 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.