分销商实际上要跟区域分开来的,单独把区域拿出来,一个区域下可能就有好多的分销商了,一对多.否则保存的时候数据是不正确的,如所有分销商,如果不分开的话那他如果是区域也一定要保存分销商级别,这样在逻辑是不正确的啊.
把分销商跟区域的对象模型分开来.
区域有个自关联,而分销商没有,具体映射如下:
区域Area:他是parent时,把它看作是Classes,他是children时把它看作是student,在理解的时候可以把它们看成是两张表.
<hibernate-mapping>
<class name="com.bjpowernode.hibernate.Area" table="t_area">
<id name="id">
<generator class="native"/>
</id>
<property name="name"/>
<many-to-one name="parent" column="pid"/>
<set name="children" lazy="extra" inverse="true">
<key column="pid"/>
<one-to-many class="com.bjpowernode.hibernate.Area"/>
</set>
</class>
</hibernate-mapping>
分销商client:
<hibernate-mapping>
<class name="com.bjpowernode.hibernate.Client" table="t_client">
<id name="id">
<generator class="assigned"/>
</id>
<property name="name"/>
<property name="bankAcctNo"/>
<property name="contactTel"/>
<property name="address"/>
<property name="zipCode"/>
<many-to-one name="clientLevel"/>
<many-to-one name="area"/>
</class>
</hibernate-mapping>