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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:05:21+00:00 2026-06-06T05:05:21+00:00

I have multiple tables in a MySQL database. Lets say they look like this:

  • 0

I have multiple tables in a MySQL database. Lets say they look like this:

  • Book:

    title, subject, publisher, book_author
    
  • Journal:

    title, subject, publisher, journal_name
    
  • Blog:

    title, subject, website, blog_author
    
  • ENews:

    title, subject, website, news_paper_name
    

The particular structure is irrelevant to the problem. In reality, there are around 20 columns that all of the tables share and more that are unique to a few or just one table. The point is, they all share some columns. I want to use Hibernate to access these, using annotated classes. I don’t want to have 5+ classes that each have 20+ redundant fields, each with an accessor and mutator. I would like a class structure something like this:

  • abstract Publication { title, subject }
    • abstract PrintPublication { publisher }
      • Book { book_author }
      • Journal { journal_name }
    • abstract Online Publicaiton { website }
      • Blog { blog_author }
      • ENews { news_paper_name }

However, I can’t for the life of me figure out how to get this to work. Each of the concrete classes is a single table in the database. I thought the solution would be a table per class (@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)), but that threw a number of interesting errors.

What is the proper solution to all of this? Besides altering the table structure. The database is not mine and I have not been given rights to change it.

  • 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-06T05:05:22+00:00Added an answer on June 6, 2026 at 5:05 am

    If there is no need for type inheritance between entities, for that purpose there is MappedSuperClass. Idea is that you define all the common persistent attributes and their mappings in mapped superclass and entities will extends it.

    Result is that mappings will apply to entity that extends mapped superclass, but from the point-of-view of persistence there is not is-a relationship between entity and mapped superclass.

    Following provides starting point:

    @MappedSuperclass
    public class Publication {
        String title;
        @Column (name="subject_of_publication")
        String subject;
    
        ...
    }
    
    @MappedSuperclass
    public class PrintPublication extends Publication {
        String publisher;
        ...
    }
    
    @Entity
    public class Book extends PrintPublication {//inherits persistent attributes
        ...
        String author;
    }
    

    You can also have mapped superclasses in other levels in entity hierarchy and override mappings in entities as needed.

    But if you have to in some point threat for example Book and Blog as one type, then mapped superclass is not way to go, because you cannot query it.

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

Sidebar

Related Questions

I have multiple tables in a mysql database and I am trying to put
I have a MySQL database with multiple tables, each of which have the same
I have a MySQL database with two tables (simplified for this question): movies table
I have a mysql database table filled with 1000+ records, lets say 5000 records.
I will have multiple tables used by different projects on the same mySql server.
My MysQL database contains multiple MyISAM tables, with each table containing millions of rows.
I have two tables in a MySQL database, Locations and Tags, and a third
I am using php and mysql. i have a question, lets say, I have
I have a MySQL database with various tables whose records can be tagged, so
I need help building a mysql query to select from multiple tables. I have

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.