一)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對(duì)象的時(shí)候,生成動(dòng)態(tài)的insert語句,如果這個(gè)字段的值是null就不會(huì)加入到insert語句當(dāng)中.默認(rèn)false
      2)<property>元素 dynamic-update屬性,設(shè)置為true,表示update對(duì)象的時(shí)候,生成動(dòng)態(tài)的update語句,如果這個(gè)字段的值是null就不會(huì)被加入到update語句中,默認(rèn)false
      3)<class>元素 dynamic-insert屬性:設(shè)置為true,表示把所有的<property>元素的dynamic-insert屬性設(shè)置為true,默認(rèn)false
      4)<class>元素 dynamic-update屬性:設(shè)置為true,表示把所有的<property>元素的dynamic-update屬性設(shè)置為true,默認(rèn)false

 

總結(jié):如果表中包含N多字段,建議把dynamic-update屬性和insert屬性設(shè)置為true,這樣在插入和修改數(shù)據(jù)的時(shí)候,語句中只包括要插入或者修改的字段.可以節(jié)省SQL語句的執(zhí)行時(shí)間,提高程序的運(yùn)行效率.(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è)置對(duì)SQL Statement影響

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