Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
107 views
in Technique[技术] by (71.8m points)

java - Why does not Hibernate set @DynamicInsert by default

Could anyone explain to me why Hibernate does not set the @DynamicInsert annotation by default and allow entities to generate an INSERT based on the currently set properties?

What's the reason for not using @DynamicInsert and, therefore, including all entity properties by default?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The dynamic inserts and updates are very useful for two reasons:

  • reducing OptimisticLockException false positives on non-overlapping write-concern property sets
  • avoiding some processing overhead related to updating indexes

However, the dynamic insert/update have drawbacks as well:

  • you cannot reuse server-side and client-side prepared statements
  • it reduces the likelihood of benefiting from batch updates] since the statement might change from one entity to the other.

So, there is no good way or bad way. It just depends on your data access patterns to figure out which of these two makes sense for a given entity.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...