1
我有一个名为Entity1
的实体,该实体与其他两个实体Entity2
和Entity3
有两个多对一的关系。当一个字段有值时,另一个字段必须为空
的Entity1
只能有我们每一个记录添加到Entity1
表时间Entity2
或Entity3
的关系。
这是Entity1
的HBM文件:
<class name="Entity1" table="t_entity1_e1" optimistic-lock="version">
<id name="id" column="e1_id">
<generator class="native"/>
</id>
<property name="libelle" column="e1_libelle"/>
<many-to-one name="entity2" column="e1_entity2" class="Entity2"/>
<many-to-one name="entity3" column="e1_entity3" class="Entity3"/>
<many-to-one name="someOtherEntity" column="e1_other_entity" class="SomeOtherEntity"/>
</class>
所以,我的意思是,当列e1_entity2
有值的另一列e1_entity1
必须为空,反之亦然。
我该怎么做?在SQL方面和在Java方面。
PS:我没有使用JPA。