假设有三个表:如何使用Hibnernate映射基于列值将表数据分为两组?
Table A (ID, NAME)
Table B (ID, NAME)
Table A-B (A_ID, B_ID, Boolean_Property)
和表A和B是由类A建模和B如下:
public class A {
private long id;
private String name;
// All the B's that belong to A where the boolean property is True
Set<B> trueBSet;
// All the B's that belong to A where the boolean property is False
Set<B> falseBSet;
}
public class B {
private long id;
private String name;
}
我怎么会这样使用Hibernate的模型?我希望能做到以下几点,但现在看来,鉴别列值不为一组属性存在:
<class name="A" table="A">
<id name="id" column="ID">
<generator class="native" />
</id>
<property name="name" column="NAME" />
<set name="trueB" table="A-B">
<key column="A_ID"/>
<many-to-many column="B_ID" class="B"/>
<discriminator column="Boolean_Property" value="True" />
</set>
<set name="falseB" table="A-B">
<key column="A_ID"/>
<many-to-many column="B_ID" class="B"/>
<discriminator column="Boolean_Property" value="False" />
</set>
</class>
非常精确的重复:http://stackoverflow.com/questions/1761901/multiple-manytomany-sets-from-one-join-table – ChssPly76 2009-11-25 21:58:05