本文主要是介绍一对多 映射文件 范例 以 customer--order 为例子,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Customer.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC"-//Hibernate/Hibernate Mapping DTD 3.0//EN""http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"><hibernate-mapping><class name="com.model.Customer" table="customers">
<!-- 设定主键的生成方式--><id name="id" column="id" type="string"><generator class="uuid"></generator></id><property name="name" column="name" type="string"></property><set name="orders" cascade="save-update" inverse="true"><key column="customer_id"></key><one-to-many class="com.model.Order"/></set> </class>
</hibernate-mapping>
Order.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC"-//Hibernate/Hibernate Mapping DTD 3.0//EN""http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"><hibernate-mapping><class name="com.model.Order" table="orders">
<!-- 设定主键的生成方式--><id name="id" column="id" type="string"><generator class="uuid"></generator></id><property name="ordernum" column="ordernum" type="string"></property><many-to-one name="customer" class="com.model.Customer" column="customer_id"></many-to-one></class>
</hibernate-mapping>
这篇关于一对多 映射文件 范例 以 customer--order 为例子的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!