Explanation of NHibernate HiLo

前端 未结 4 1110
暖寄归人
暖寄归人 2020-12-23 16:50

I\'m struggling to get my head round how the HiLo generator works in NHibernate. I\'ve read the explanation here which made things a little clearer.

My understanding

4条回答
  •  佛祖请我去吃肉
    2020-12-23 17:30

    I believe your understanding is more or less correct. The max_lo parameter is simply used to determine the number of Ids available for any given Hi value.

    My best guess is that NHibernate's default max_lo value is 32768. Thus a Hi value of 1 would start your Ids at 32768 and run you right up to 65535. A Hi value of 2 would start at 65536 and run up another max_lo Ids.

    Basically you use the max_lo value to control Id fragmentation. 32768 is likely not the optimal value for every situation.

    It is important to note however that this only works within the scope of a SessionFactory. If you are stopping/starting your application and reinitializing the SessionFactory a whole bunch, it's going to increment the Hi value upon startup anyway and you're going to see your Ids jump pretty quickly.

提交回复
热议问题