user1802311
user1802311

Reputation: 71

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?

Upvotes: 1

Views: 703

Answers (2)

pedjaradenkovic
pedjaradenkovic

Reputation: 241

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.

Upvotes: 1

Atropo
Atropo

Reputation: 12531

You want to to prevent Hibernate from updating the children entities you should change the cascade type, remove cascade=all.

Upvotes: 0

Related Questions