many-to-one避免出现No row with the given identifier exists的配备方法

many-to-one避免出现No row with the given identifier exists的配置方法

如下:

表Space的Space.hbm.xml文件中关联了创建者的对象builder,这时在many-ton-one中设置fetch="join"和not-null="true",这时产生的sql语句就变成了内联查询inner join而不是左外联查询,这样就可以避免在查询中遇到关联的对象为null的情况了(比如关联的用户已经被删除,但是Space的数据没有删除掉)

 <many-to-one name="builder" column="userId"
            class="org.dengzh.vo.Users" lazy="false" insert="false"
            update="false" fetch="join" not-null="true">
 </many-to-one>