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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:06:04+00:00 2026-05-16T02:06:04+00:00

I have 2 existing tables in my database. Let’s call them Table and Chair

  • 0

I have 2 existing tables in my database.
Let’s call them Table and Chair for now.
Both these tables are mapped as entities in Hibernate

Both these tables have existed in my database for some time now, and they have their own, auto generated, ID’s as primary keys.

Now however, I want to group those entities under the very logical Furniture interface in my Java code so I can have a List in my House class.

I’ve looked into Hibernate inheritance but don’t seem to figure it out.
How can I let my House class get a list of all the Furniture it owns? And which inheritance mapping strategy should I use?

Thanks,
Bart

  • 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-16T02:06:05+00:00Added an answer on May 16, 2026 at 2:06 am

    You are on the right track. If you create Furniture interface, or base class, and have Table and Chair implement/extend that type, you should be good to go. You can then have a

    List<Furniture> 
    

    for your House.

    The only case where you would need to modify your mapping is if you want to implement any of the polymorphic mapping strategies outlined in the hibernate documentation. Some options are

    1. to create a Furniture table and have all Chairs/Tables in that table instead (One table per class hierarchy). You do not have to do this. In this case your table would have all the properties of both classes, so not all columns would be used depending on the type being persisted. There would be a ‘discriminator’ column so hibernate could tell the type of a row.

    2. You want to create a Furniture table, and refactor/normalize your Table/Chair tables so that all common fields are pulled into the Furniture table. You keep the Table and Chair tables. This is another type of polymorphic mapping (check the docs)

    3. Other options in the hibernate docs.

    Option 1 is the preferred strategy in the hibernate docs, I believe.

    But to get down to it, you don’t have to do any of these — your entities can extend/inherit from other types without any special mapping considerations, if you are willing to have the duplicate columns in the tables.

    I would write some simple JUnit or whatever tests and try it out.

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

Sidebar

Related Questions

I have an existing database with the table Transactions in it. I have added
Let's say I have two existing tables, dogs and cats: dog_name | owner ---------+------
Background information Let's say I have two database servers, both SQL Server 2008. One
I have 2 databases, and I want to transport an existing table containing a
Let's say that I have a vast quantity of restaurant reviews in a database
I need to duplicate several tables in a single database. Basically we have an
I have an existing database that I'm access with LINQ to Entity in .NET
I am enhancing an existing web application and I have created a new database
I have two tables in my Database.This can increase later on.I want to add
I have an ASP.NET application with existing business classes and a database schema. (which

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.