栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

何时在hibernate状态下使用DiscriminatorValue注释

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

何时在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。

鉴别符通常在SINGLE_TABLE继承中使用,因为您需要一个列来标识记录的类型。

示例:您有一个学生类和两个子类:GoodStudent和BadStudent。Good和BadStudent数据都将存储在1个表中,但是我们当然需要知道类型,然后才是(DiscriminatorColumn和)DiscriminatorValue出现的时间。

注释学生班

@Entity@Table(name ="Student")@Inheritance(strategy=SINGLE_TABLE)@DiscriminatorColumn(discriminatorType = DiscriminatorType.STRING,    name = "Student_Type")public class Student{     private int id;     private String name;}

坏学生班

@Entity@DiscriminatorValue("Bad Student")public class BadStudent extends Student{  //pre here}

优秀学生班

@Entity@DiscriminatorValue("Good Student")public class GoodStudent extends Student{ //pre here}

因此,现在 Student 表将具有一个名为 Student_Type 的列,并将其中保存Student 的
DiscriminatorValue

-----------------------id|Student_Type || Name |--|---------------------|1 |Good Student || Ravi |2 |Bad Student  || Sham |-----------------------

请参阅我上面发布的链接。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/406105.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号