Doesn't dirty checking technology have bulk operations?

Hello, I’m Hibernate newbie.

I can now write object-oriented code thanks to Hibernate’s dirty checking technology.

An entity can be modified in many different ways, but conversely, many entities can have the same specific modifications.

Even though N entities make the same modification, I know that N queries are made according to dirty checking technology.

I thought this part was inefficient and thought there must be a better way. But I haven’t found a way yet.

Of course, I know that if I use native query, I can fix it with a single query.

But I want to write code in an object-oriented way, and I want to use dirty checking to modify that aspect.

I’m curious if anyone has the same problem as me and if there is a solution.

If my explanation is insufficient, please feel free to tell me!

Why do you think it is inefficient? Have you measured the time it takes and noticed that it is too slow for your use case?

If you plan to update thousands of entities in the same way, you should rather consider using a HQL DML statement to do the update e.g. update MyEntity e set e.myAttribute = '' where ...

I didn’t specifically measure the time, but I thought it was inefficient based on the number of queries that occurred.

I was just wondering if there was a simple way to process thousands of entities in one query using dirty checking techniques!

There is not. When using JDBC batching, the network latency effect of sending multiple commands is reduced, but that’s the best that you can do with dirty checking.

Thanks for the reply! I think I can solve my problem!