简体   繁体   中英

Why does Hibernate execute multiple queries for updating children when parent is updating?

I have a many-to-one relationship with inverse="false" and cascade="all" . When I update the parent, there is an update query for this parent object and multiple update queries - one for each child object in child's collection.

Could you tell me why there are these queries for children? And how might I avoid them?

If you have cascade="all" that means that every operation on parent entity will call same operation on child entities. So you have to remove cascade=all if you want not to cascade operations on child entities from association.

But you should be careful with that configuration, because if you don't have cascade persist (for example) created child entity will not be persisted even it is created regularly, but you have to explicitly call save on every child entity.

You can read more about cascade types on this thread.

您要防止Hibernate更新子实体,应更改级联类型,删除cascade=all

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