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 }
- abstract
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.