Hibernate各种映射关系总结
2009-10-30 00:00:00 来源:WEB开发网5 继承mapping
第一类继承映射
1 对象模型
Animal
private int id
private String name
private Boolean sex
--------------------------------------------------
public class Bird extends Animal
private int height
--------------------------------------------------
public class Pig extends Animal
private int weight
2 mapping 文件
Xml代码
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.nintenyun.hibernate">
<class name="Animal" table="t_animal" >
<id name="id" >
<generator class="native"/>
</id>
<discriminator column="type" type="string"></discriminator>
<property name="name"/>
<property name="sex"/>
<subclass name="Pig" discriminator-value="P">
<property name="weight"/>
</subclass>
<subclass name="Bird" discriminator-value="B">
<property name="height"/>
</subclass>
</class>
</hibernate-mapping>
赞助商链接