29

Using dynamic-update or dynamic-insert has positive, though generally slight only on performance, as also mentioned by http://www.mkyong.com/hibernate/hibernate-dynamic-update-attribute-example/

But the reference documentation mentions that this could have negative performance effects also as mentioned below in http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html#mapping-declaration-class :

Although these settings can increase performance in some cases, they can actually decrease performance in others.

Can anybody please suggest some example/scenario mentioning negative performance impact of the same?

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
Sandeep Jindal
  • 14,510
  • 18
  • 83
  • 121

4 Answers4

59

Hibernate caches the actual INSERT/SELECT/UPDATE SQL strings for each entity and the obvious benefit is that it doesn't have to compute the SQL when you want to persist, find or update an entity.

However, when using dynamic-insert or dynamic-update, Hibernate has to generate the corresponding SQL string each time and there is thus a performance cost on the Hibernate side.

In other words, there is a trade-off between overhead on the database side and on the Hibernate side.

My point of view is that dynamic insert and dynamic update can be interesting for tables with a fat blob column or tables with a huge number of columns. In other cases, I'm not convinced that dynamic insert or update always means performance boost (I do not use them by default). But as always, you should measure it.

See also

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
7

I think many indices also slow down updates and inserts, so, beside large columns, dynamic-update should be good for tables with great width/content per row and many indices. You know, in "real life", databases aren't always with small, normalized tables...

Rebuilding indices on large tables may take much longer than the overhead for creating and parsing SQL queries.

Erik Hart
  • 1,114
  • 1
  • 13
  • 28
1

The other reason is when updating a previously detached object. For that to work the record first needs to be fetched from the db, as a detached object isn't in the session cache. Hence dynamic update in this case requires an extra round trip to perform the initial fetch.

codefly
  • 11
  • 1
0

For small table dynamic is not good way since you have to waste time to execute extra step to judge which column shoud be updated and inserted. For big table it has huge performance both for traffic and sql command execution speed since there are much fewer data to fetch, query annd trasfer.

Yan Chun Tang
  • 31
  • 1
  • 3
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – MD. RAKIB HASAN Dec 02 '21 at 06:18