何时在hibernate中使用DiscriminatorValue注解 [英] When to use DiscriminatorValue annotation in hibernate
问题描述
在hibernate中使用DiscriminatorValue注解的最佳场景是什么?什么时候是最好的?
概念最多:http://docs.oracle.com/javaee/6/tutorial/doc/bnbqn.html
http://www.javaworld.com/javaworld/jw-01-2008 /jw-01-jpa1.html?page=6
要理解鉴别器,首先您必须了解继承策略:SINGLE_TABLE,JOINED,TABLE_PER_CLASS。
Discriminator常用于SINGLE_TABLE继承,因为您需要一列来标识记录的类型。
示例:你有一个班级学生和两个小班:好学生和坏学生。 Good和BadStudent数据都将存储在1个表中,但我们当然需要知道类型,这是DiscriminatorColumn的用途。请参阅上面张贴的链接。
What and when is the best scenario to use DiscriminatorValue annotation in hibernate?
These 2 links help me understand the inheritance concept the most:
http://docs.oracle.com/javaee/6/tutorial/doc/bnbqn.html
http://www.javaworld.com/javaworld/jw-01-2008/jw-01-jpa1.html?page=6
To understand discriminator, first you must understand the inheritance strategies: SINGLE_TABLE, JOINED, TABLE_PER_CLASS.
Discriminator is commonly used in SINGLE_TABLE inheritance because you need a column to identify the type of the record.
Example: You have a class Student and 2 sub-classes: GoodStudent and BadStudent. Both Good and BadStudent data will be stored in 1 table, but of course we need to know the type and that's when DiscriminatorColumn will come in. See the links I posted above.
这篇关于何时在hibernate中使用DiscriminatorValue注解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!