多对多测试
1.ID问题:
generator class="increment"
而在程序里执行setId就会报异常,因为ID是自动生成的。
new出来的对象的ID值为0,但是saveOrUpdate要求ID为NULL时才执行SAVE,在其它情况下执行UPDATE。
解决方案:
数据库加上 auto incre
映射文件使用 generator class=" native"
对象不执行 setId 就可以啦
2.关系表:
agent 7,8------------->customer8
customer8,9--------->agent7
agentid | customerid |
7 | 8 |
7 | 9 |
8 | 8 |
7 | 8 |
3.inverse的作用:
当customer的inverse为true时:
<set name="agents" table="agent_customer" inverse="true" lazy="true" cascade="all" >
<key column="customerid"> </key>
<many-to-many class="com.oliver.Agent" column="agentid" outer-join="auto" />
</set>
agent 7,8------------->customer8将不会被加入到关系表中。