简体   繁体   English

更改休眠关系映射(从单向到双向)

[英]Change hibernate relationship mapping (from unidirectional to bidirectional)

I'm working in a existing web application,and the entities have an unidirectional hibernate relationship mapping.我在现有的 Web 应用程序中工作,并且实体具有单向休眠关系映射。

So I would like to change it to bidirectional mapping to have more flexible hql queries.所以我想将其更改为双向映射以具有更灵活的 hql 查询。

My question is that a good idea and what is the impact for the existing data ?我的问题是这是个好主意,对现有数据有什么影响?

Thank you.谢谢你。

There is no impact on your data, you just have to make sure you update both sides of the association whenever you associate/remove a Child entity.对您的数据没有影响,您只需确保在关联/删除子实体时更新关联的双方。

From a performance perspective, the one-to-many side association should only be used when there is a relatively small amount of Child entities.从性能的角度来看, one-to-many侧关联应该只在子实体数量相对较少的情况下使用。

If you have tens of thousands of Child records, Hibernate would have to fetch all of them when the collection is accessed and in this case, a query is a much better approach.如果您有数以万计的 Child 记录,则 Hibernate 必须在访问集合时获取所有这些记录,在这种情况下,查询是一种更好的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM