2
votes

In my database there are two three tables. The first one, table ABSTRACT, holds three columns

id, type, someText

This table contains all abstract information for the abstract class abstract. Now the two tables CONCRETEONE and CONCRETETWO contain all information for the concrete classes concreteOne and concreteTwo. Now I know I could use the table per subclass strategy from hibernate to create a mapping with inheritance. But as I have a column that marks the type of the concrete implementation could it be possible to create some mixed behaviour like a table per subclass strategy with an discriminator?

1
why do you need the discriminator? why don't you go with plain "table per subclass"?cherouvim
Maybe this could decrease the performance overhead as theoretically the outer joins could be avoided when querying for the abstract class.Sebastian Müller

1 Answers

2
votes

Hibernate inheritance mapping strategies should be selected based on the database design.

If you can not change the database design, then stick with the best strategy for the current DB design. i.e table per subclass strategy.

If you can change the database design, forget about Hibernate first, focus on which DB table design is better for your application. Some factors to consider, a) How the data will be fetched/used? Lets say, if most of the time, the logic not concern about differentiating CONCRETEONE and CONCRETETWO, then no point of going for sub tables. b) How many additinal columns are required to CONCRETEONE and CONCRETETWO? If you have so many columns specific to sub tables then "Table per class herarchy" is not a good idea. c) Columns specific to sub tables should not be "NOT-NULL".

Hope this will help.