ManyToMany双向
实体类:


映射文件:


测试add:

测试load:

结论:使用ManyToMany的时候无论使用哪一方来维护关系都比较麻烦,而且很多时候关联表中需要加入其它属性,所以在开发中经常使用两个一对多来代替使用多对多。
两个一对多来代替使用多对多
实体类:



映射文件:



测试add:

测试load:

总体来说,最佳实践就是一般不使用双向关联,特别不建议使用一的这一方的关联
因为从一的这一端取关联对象的时候可能涉及到分页操作,所以基本不会使用
所以在设计的时候,不是特殊情况,不要使用双向关联.
网友评论