简体   繁体   中英

hibernate inheritance for an online library/shop design implementation choice

I wish to implement an online library in hibernate. Here is my sql sschema:

SQL模式

Between Book and Programming book I am thinking of using hibernate inheritance of type table per subclass joined. I designed the sql schema this way because I don't see the point of having the same columns duplicate in 10 tables. Maybe I need to add one more common column, I don't want to do it in 10 tables. But this means that whenever a Book is needed somewhere, a huge join would be made between all the subtables ( I have only 2, but I could have 50 book types!!! ). The same stuff applies if for example I would have had an online shop: I would have had Product, Tv, Laptop, Phone, etc...).

What design can help me avoid this behaviour?

My thoughts are:

  • I could duplicate all the columns in all the subtables, and thus, don't use inheritance at all, treat them like different entities. The only thing here is that I will have to tie every specific book table of other tables ( authors, etc )
  • I could avoid using inheritance, keep the current sql schema but use unidirectional association ( a ProgrammingBook has a Book, etc )

What option do you guys recommend?

Kind regards,

From experience, when using inheritance with Hibernate, you should prefer the Table per Hierarchy point of view, with a discriminator.

Here's a thread that could help you pick an answer : How can you represent inheritance in a database?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM