一对多关系式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)" ﹤set name="对应实体类中的那个集合的属性" ﹤id name="id" column="对应表的主键字段名" unsaved-value="null" ﹥ ﹤generator class="native"/﹥ |
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技术就是围绕着配置文件去发展。
【编辑推荐】