package cn.itcast.domain;java
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;app
public class Customer implements Serializable{dom
private static final long serialVersionUID = 1L;
private Long custId;
private String custName;
private String custSource;
private String custIndustry;
private String custLevel;
private String custAddress;
private String custPhone;
private Set<LinkMan> linkMans = new HashSet<LinkMan>();//应该要实例化ide
public Long getCustId() {
return custId;
}
public void setCustId(Long custId) {
this.custId = custId;
}
public String getCustName() {
return custName;
}
public void setCustName(String custName) {
this.custName = custName;
}
public String getCustSource() {
return custSource;
}
public void setCustSource(String custSource) {
this.custSource = custSource;
}
public String getCustIndustry() {
return custIndustry;
}
public void setCustIndustry(String custIndustry) {
this.custIndustry = custIndustry;
}
public String getCustLevel() {
return custLevel;
}
public void setCustLevel(String custLevel) {
this.custLevel = custLevel;
}
public String getCustAddress() {
return custAddress;
}
public void setCustAddress(String custAddress) {
this.custAddress = custAddress;
}
public String getCustPhone() {
return custPhone;
}
public void setCustPhone(String custPhone) {
this.custPhone = custPhone;
}
public Set<LinkMan> getLinkMans() {
return linkMans;
}
public void setLinkMans(Set<LinkMan> linkMans) {
this.linkMans = linkMans;
}
@Override
public String toString() {
return "Customer [custId=" + custId + ", custName=" + custName + ", custSource=" + custSource
+ ", custIndustry=" + custIndustry + ", custLevel=" + custLevel + ", custAddress=" + custAddress
+ ", custPhone=" + custPhone + "]";
}
}
this
<?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="cn.itcast.domain.Customer" table="cst_customer">
<id name="custId" column="cust_id">
<generator class="native"></generator>
</id>
<property name="custName" column="cust_name"></property>
<property name="custSource" column="cust_source"></property>
<property name="custIndustry" column="cust_industry"></property>
<property name="custLevel" column="cust_level"></property>
<property name="custAddress" column="cust_address"></property>
<property name="custPhone" column="cust_phone"></property>
<!--
set标签:映射集合属性
name属性:集合属性的名字
cascade属性:配置级联,save-update:级联保存或更新
inverse="true",表示让一方(主表)放弃外键维护权利
-->
<set name="linkMans" inverse="true">
<!--
key标签:映射外键的
column属性:指定外键列名
-->
<key column="lkm_customer_id"></key>
<!--
one-to-many标签:指定当前实体和对方(联系人)是一对多的关系
-->
<one-to-many class="cn.itcast.domain.LinkMan"/>
</set>
</class>
</hibernate-mapping>.net
package cn.itcast.domain;hibernate
import java.io.Serializable;xml
public class LinkMan implements Serializable {对象
private static final long serialVersionUID = 1L;
private Long lkmId;
private String lkmName;
private String lkmGender;
private String lkmPhone;
private String lkmMobile;
private String lkmEmail;
private String lkmPosition;
private String lkmMemo;
private Customer customer;
public Long getLkmId() {
return lkmId;
}
public void setLkmId(Long lkmId) {
this.lkmId = lkmId;
}
public String getLkmName() {
return lkmName;
}
public void setLkmName(String lkmName) {
this.lkmName = lkmName;
}
public String getLkmGender() {
return lkmGender;
}
public void setLkmGender(String lkmGender) {
this.lkmGender = lkmGender;
}
public String getLkmPhone() {
return lkmPhone;
}
public void setLkmPhone(String lkmPhone) {
this.lkmPhone = lkmPhone;
}
public String getLkmMobile() {
return lkmMobile;
}
public void setLkmMobile(String lkmMobile) {
this.lkmMobile = lkmMobile;
}
public String getLkmEmail() {
return lkmEmail;
}
public void setLkmEmail(String lkmEmail) {
this.lkmEmail = lkmEmail;
}
public String getLkmPosition() {
return lkmPosition;
}
public void setLkmPosition(String lkmPosition) {
this.lkmPosition = lkmPosition;
}
public String getLkmMemo() {
return lkmMemo;
}
public void setLkmMemo(String lkmMemo) {
this.lkmMemo = lkmMemo;
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
@Override
public String toString() {
return "LinkMan [lkmId=" + lkmId + ", lkmName=" + lkmName + ", lkmGender=" + lkmGender + ", lkmPhone="
+ lkmPhone + ", lkmMobile=" + lkmMobile + ", lkmEmail=" + lkmEmail + ", lkmPosition=" + lkmPosition
+ ", lkmMemo=" + lkmMemo + ", customer=" + customer + "]";
}
get
}
<?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="cn.itcast.domain.LinkMan" table="cst_linkman"> <id name="lkmId" column="lkm_id"> <generator class="native"></generator> </id> <property name="lkmName" column="lkm_name"></property> <property name="lkmGender" column="lkm_gender"></property> <property name="lkmPhone" column="lkm_phone"></property> <property name="lkmMobile" column="lkm_mobile"></property> <property name="lkmEmail" column="lkm_email"></property> <property name="lkmPosition" column="lkm_position"></property> <property name="lkmMemo" column="lkm_memo"></property> <!-- many-to-one:指定当前实体与对方是多对一的关系 name属性:指定当前实体中一方的对象属性 class属性:指定一方的全路径名 column属性:指定外键列名 ,须要与一方中指定的外键列名一致 --> <many-to-one name="customer" class="cn.itcast.domain.Customer" column="lkm_customer_id" cascade="delete" lazy="false"></many-to-one> </class> </hibernate-mapping>