一对多关系式Hibernate中的重要知识。感觉在Hibernate学习中最重要的也是最难的问题就是配置文件了,对于Hibernate一对多关系的配置***.hbm.xml现总结如下:
??xml version="1.0" encoding="gbk"?? ?!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"? ?hibernate-mapping package="此处填写包文件" ? ?class name="一对多中一的实体类的类名" table="所对应的数据库的表名" ? ?id name="所对应的实体类的属性(id)" column="所对应的数据表的字段(**_id)" unsaved-value="null" ? ?generator class="native"/? ?/id? ?property name="对应数据表中其他的字段" ??/property? ?set name="对应实体类中的那个集合的属性" inverse="true" lazy="true" cascade="save-update" ??key column="对应其外键的字段 "/??one-to-many class="对应一对多中多的实体类的类名"/? ?/set??/class??class name="对应一对多中多的实体类的类名" table="相对应的数据表名" ? ?id name="id" column="对应表的主键字段名" unsaved-value="null" ? ?generator class="native"/??/id??property name="对应数据表中的其他字段" ??/property??many-to-one name="对应一对多中一的实体类的属性" column="对应实体类中的那个集合的属性" ??/many-to-one??/class??/hibernate-mapping? |
Hibernate一对多关系的配置代码如下:
?!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"? ?hibernate-mapping package="entity.test" ? ?class name="Person" table="Person1" ? ?id name="pid" column="p_id" unsaved-value="null" ? ?generator class="native"/? ?/id? ?property name="name" ??/property? ?set name="computers" inverse="true" lazy="true" cascade="save-update" ? ?key column="p_id"/? ?one-to-many class="Computer"/? ?/set? ?/class? ?class name="Computer" table="Computer" ? ?id name="id" column="c_id" unsaved-value="null" ? ?generator class="native"/? ?/id? ?property name="name" ??/property? ?many-to-one name="person" column="p_id" ??/many-to-one? ?/class? ?/hibernate-mapping? ?!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"? ?hibernate-mapping package="entity.test" ? ?class name="Person" table="Person1" ? ?id name="pid" column="p_id" unsaved-value="null" ? ?generator class="native"/? ?/id? ?property name="name" ??/property? ?set name="computers" inverse="true" lazy="true" cascade="save-update" ? ?key column="p_id"/? ?one-to-many class="Computer"/? ?/set? ?/class? ?class name="Computer" table="Computer" ? ?id name="id" column="c_id" unsaved-value="null" ? ?generator class="native"/? ?/id? ?property name="name" ??/property? ?many-to-one name="person" column="p_id" ??/many-to-one? ?/class? ?/hibernate-mapping? |
整个的Hibernate技术就是围绕着配置文件去发展。