分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > IT知识

Hibernate映射关系配置(五)

发布时间:2023-09-06 01:13责任编辑:蔡小小关键词:配置Hibernate

多表继承:

Bean:

public class Person implements Serializable{ ???private int id ; ???????private String name ; ???????private int age ;}public class Student extends Person implements Serializable { ???????private String dream ; ???????private Date birthday ;}public class Teacher extends Person implements Serializable{ ???private String job ; ???????private boolean merry ;}

xml(在同一个表中,加一个字段来区分类型):

Person.hbm.xml:<class name = "Person" discriminator-value="p"> ???????<id name = "id"> ???????????<generator class="native" /> ???????</id> ???????<!-- discriminator 是新建一个列,此列用来区分对象具体的类型 ?????????????discriminator-value 定义插入一个具体的对象的时候,自动向type列中插入指定的值 ???????--> ???????<discriminator column="type" /> ???????<property name="name" /> ???????<property name="age" /> ???????????????<subclass name = "Teacher" discriminator-value="t"> ????????????<property name="job" /> ????????????<property name="merry" /> ???????</subclass> ???????????????<subclass name = "Student" discriminator-value="s"> ????????????<property name="dream" /> ????????????<property name="birthday" /> ???????</subclass> ???</class> ???

xml(在不同表中):

Person.hbm.xml:<class name = "Person"> ???????<id name = "id"> ???????????<generator class="native" /> ???????</id> ???????????????<property name="name" /> ???????<property name="age" /> ???????????????<joined-subclass name="Teacher" table="Teacher"> ???????????<key column="pid" /> ???????????<property name="job" /> ???????????<property name="merry" /> ???????</joined-subclass> ???????????????<joined-subclass name="Student" table="Student"> ???????????<key column="pid" /> ???????????<property name="dream" /> ???????????<property name="birthday" /> ???????</joined-subclass> ???????????</class>

Hibernate映射关系配置(五)

原文地址:http://www.cnblogs.com/hyl-home/p/7577019.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved