开发者

Mixing table per subclass and per hierarchy in hibernate

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

id, type, someText

This table contains all abs开发者_JAVA技巧tract 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜