简体   繁体   中英

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.

So I would like to change it to bidirectional mapping to have more flexible hql queries.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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