views:

115

answers:

1

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?

+2  A: 

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.

Sujee
a) perhaps you are right and it will very rarely happen that I want to query for the abstract class b)many additional columns, therefore I am asking c) alrightI take a look at http://www.javalobby.org/java/forums/t18300.html, maybe this will help me
Xelluloid