一)default statements generated on startup
By default, Hibernate creates SQL statements for each persistent class on startup.These statements are simple create, read, update, and delete operations for reading a single row, deleting a row, and so on.
the generated SQL statement updates all columns, and if the value of a particular column isn’t modified, the statement sets it to its old value.


二)dynamic statements generated at runtime
      1)<property>元素 dynamic-insert屬性:設(shè)置為true,表示insert對象的時候,生成動態(tài)的insert語句,如果這個字段的值是null就不會加入到insert語句當(dāng)中.默認false
      2)<property>元素 dynamic-update屬性,設(shè)置為true,表示update對象的時候,生成動態(tài)的update語句,如果這個字段的值是null就不會被加入到update語句中,默認false
      3)<class>元素 dynamic-insert屬性:設(shè)置為true,表示把所有的<property>元素的dynamic-insert屬性設(shè)置為true,默認false
      4)<class>元素 dynamic-update屬性:設(shè)置為true,表示把所有的<property>元素的dynamic-update屬性設(shè)置為true,默認false

 

總結(jié):如果表中包含N多字段,建議把dynamic-update屬性和insert屬性設(shè)置為true,這樣在插入和修改數(shù)據(jù)的時候,語句中只包括要插入或者修改的字段.可以節(jié)省SQL語句的執(zhí)行時間,提高程序的運行效率.(In some situations, such as a legacy table with hundreds of columns where the SQL statements will be large for even the simplest operations (say, only one column needs updating), you have to turn off this startup SQL generation and switch to dynamic statements generated at runtime.)


其他屬性設(shè)置對SQL Statement影響

      1)<property>元素 insert屬性:設(shè)置為false,在insert語句中不包含這個字段,表示永遠不會被插入,默認true
      2)<property>元素 update屬性:設(shè)置為false,在update語句中不包含這個字段,表示永遠不會被修改,默認true
      3)<class>元素 mutable屬性:設(shè)置為false就是把所有的<property>元素的update屬性設(shè)置為了false,說明這個對象不會被更新,默認true