Hibernate Table Inherit
来源:互联网 发布:嘉兴南湖行知小学 编辑:程序博客网 时间:2024/05/29 16:15
1、理解如何映射
这种策略是使用union-subclass标签来定义子类的。每个子类对应一张表,而且这个表的信息是完备的,
即包含了所有从父类继承下来的属性映射的字段(这就是它跟joined-subclass的不同之处,
joined-subclass定义的子类的表,只包含子类特有属性映射的字段)。实现这种策略的时候,有如下步骤:
父类用普通<class>标签定义即可
子类用<union-subclass>标签定义,在定义union-subclass的时候,需要注意如下几点:
Union-subclass标签不再需要包含key标签(与joined-subclass不同)
Union-subclass标签,既可以被class标签所包含(这种包含关系正是表明了类之间的继承关系),
也可以与class标签平行。 当Union-subclass标签的定义与class标签平行的时候,需要在Union-subclass
标签中,添加extends属性,里面的值是父类的全路径名称。子类的其它属性,像普通类一样,
定义在Union-subclass标签的内部。这个时候,虽然在union-subclass里面定义的只有子类的属性,
但是因为它继承了父类,所以,不需要定义其它的属性,在映射到数据库表的时候,依然包含了父类的所
有属性的映射字段。
注意:在保存对象的时候id是不能重复的(不能使用自增生成主键)
每个具体类映射成一张表
t_pig
id
name
sex
weight
1
猪猪
true
100
t_bird
id
name
sex
height
2
鸟鸟
false
50
session{
map{
key=Animal+id
}
}
<class name="Animal" table="t_animal" abstract=”true”>
<id name="id">
<generator class="assigned"></generator>
</id>
<property name="name"></property>
<property name="sex"></property>
<union-subclass name="Pig" table="t_pig">
<property name="weight"></property>
</union-subclass>
<union-subclass name="Bird" table="t_bird">
<property name="height"></property>
</union-subclass>
</class>
- Hibernate Table Inherit
- inherit
- hibernate @table
- about inherit
- JAVA Inherit
- c++inherit
- c++ inherit
- Closure&Inherit
- hibernate生成table
- Hibernate Table annotations
- Hibernate的@Table注解
- org.hibernate.mapping.Table.java
- hibernate使用table生成主键
- Hibernate之@Entity,@Table,@Id
- hibernate@Table(catalog=" ")配置
- inherit in javascript
- Perl Inherit Instance
- public private protected inherit
- AIX常用命令集 ---只要用到过的,就不断往里增加
- Windows via C/C++ 学习(5)Windows中使用的Unicode和ANSI函数
- memcached的分布式算法
- 文件操作
- 解析xml文件
- Hibernate Table Inherit
- c++深入专题1--句柄
- How Computers Boot Up
- 面向对象设计模式原则
- tar.gz文件解压 linux
- 生成xml文件例子
- Hibernate 的四种继承关系
- 再论数组与指针
- minix masterboot解读