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

  • Home
  • SEARCH
  • 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 6146849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:01:00+00:00 2026-05-23T19:01:00+00:00

I met exception when using annotated joined subclass, i don’t know how to correct

  • 0

I met exception when using annotated joined subclass, i don’t know how to correct it, please help.

Exception is: org.hibernate.MappingException: Unknown entity: B

Code:

Class A

@Entity
@Table(name="table_a")
@Inheritance(strategy=InheritanceType.JOINED)   
public class A {
    // uses composite key
    @Id
    @Column(name="sid")
    private String sid;

    @Id
    @Column(name="uid")
    private String uid;

    .....
}

Class B

@Entity
@Table(name="table_b")
public class B extends A {
    // inherited sid and uid from A
    @Id
    @Column(name="xid")
    private String xid;

    @Column(name="name")
    private String name;
    ......
}

Tables

create table_a(sid varchar, uid varchar);
create table_b(sid varchar, uid varchar, xid varchar, name varchar);

Hibernate.cfg.xml

<hibernate-configuration>
    <session-factory>
        .....
        <mapping class="A"/>
        <!-- no need to map B here, right?
        <mapping class="B"/>
        -->
        .....
    </session-factory>
</hibernate-configuration>

TestClass

public class HibernateTest {
    public static void main(String[] args) throws Exception {
        SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
        Session session = sessionFactory.openSession();
        session.beginTransaction();
        B temp = new B();
        temp.setSid(1);
        temp.setUid(2);
        temp.setXid(3);
        B target = session.get(B.class, temp);
        System.out.println("---------------" + target.getName());
        session.getTransaction().commit();
        session.close();
   }
}

Exception:

Exception in thread "main" org.hibernate.MappingException: Unknown entity: B
  • 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-23T19:01:02+00:00Added an answer on May 23, 2026 at 7:01 pm

    You have <mapping class="B"/> commented out with a question asking if it’s needed. You need it.

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

Sidebar

Related Questions

i met a very strange PHP behaviour, i don't understand why it behaves like
guys I know this question is very basic but I've met in few publications
Using Moq, I'd like to be able to verify that certain conditions are met
Calling a .net SOAP1.1 web service from android using ksoap2 lib I met a
I met some compilation error but do not know what the problem is. The
Have you guys met something similar? Exception type: System.ComponentModel.Win32Exception Exception message: The operation completed
I have a Java webapp using Hibernate and MySQL. If the site isn't used
I have met a problem with virtualbox, I hope someone could help me here,
I met an interesting issue about C#. I have code like below. List<Func<int>> actions
I met a problem which is very strange, my company uses Visual Source Safe

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.