hilo

HiLO for the Entity Framework

笑着哭i 提交于 2019-11-30 17:34:27
Has anyone implemented a HiLO key generator for the Entity Framework. Read more about HiLo here: I recommend that you read http://fabiomaulo.blogspot.com/2009/02/nh210-generators-behavior-explained.html for a detailed explanation of the downsides of choosing identity. Yes, someone has implemented HiLO for Entity Framework. I haven't tested it myself though: http://joseoncode.com/2011/03/23/hilo-for-entityframework/ Thanks for the answers I think I just have to wait :-) The EF is moving in the right direction love the CTP5. I need to comment on the answer from "Rap". Using random Guid's as

HiLO for the Entity Framework

半腔热情 提交于 2019-11-30 00:57:06
问题 Has anyone implemented a HiLO key generator for the Entity Framework. Read more about HiLo here: I recommend that you read http://fabiomaulo.blogspot.com/2009/02/nh210-generators-behavior-explained.html for a detailed explanation of the downsides of choosing identity. 回答1: Yes, someone has implemented HiLO for Entity Framework. I haven't tested it myself though: http://joseoncode.com/2011/03/23/hilo-for-entityframework/ 回答2: Thanks for the answers I think I just have to wait :-) The EF is

hilo高低位算法的优点和用途(非Hibernate主键策略)

孤街醉人 提交于 2019-11-27 03:10:07
开门见山地说,hilo高低位算法的用途,或者说目前为止我所见过的用途,就是—— 编号生成! 通常订单编号、产品编号、物流编号、工人编号、批次编号等等各种各样的编号,都是由数字构成,有得会加一些前缀后缀,例如淘宝订单号。这种编号比较符合我们的理解和写记习惯。下面说一下几点不合理的编号设计。 使用数字型的自增长、序列。这用来表示唯一性没问题,但是当我们遇到像订单编号这种,需要一定长度不太合适。 编号需要一定长度,可能你会想到uuid。uuid生成的包含字符,无序、无意义而且也比较长,不符合我们的写记习惯,所以uuid做编号也是不合理的。 使用时间戳来当编号,在并发的情况下精确到毫秒也有可能发生唯一性问题 使用随机数加前后缀当编号,很多语言的随机数都是伪随机,例如用java每次都new Random(),并发的情况下有可能取出一样的数字,就算不并发,谁能保证不会随机到之前生成过的数字? 合理的做法是用表来管理数字主键,每次取出来拼接前缀或后缀来当编号,然后+1,就像oracle的序列一样,因为有些数据库没有序列,所以通常为了统一使用表来管理。 hilo高低位算法在这个时候登场了! 它解决了一个效率问题——每次取id号都要从数据库查一遍。 详细分析高低位算法: /*首先有这几个静态变量和常量*/ long static final maxLo;//最大低位 long static hi=0

Hibernate, @SequenceGenerator and allocationSize

人走茶凉 提交于 2019-11-26 12:06:37
We all know the default behaviour of Hibernate when using @SequenceGenerator - it increases real database sequence by one , multiple this value by 50 (default allocationSize value) - and then uses this value as entity ID. This is incorrect behaviour and conflicts with specification which says: allocationSize - (Optional) The amount to increment by when allocating sequence numbers from the sequence. To be clear: I do not bother about gaps between generated IDs. I care about IDs that are not consistent with underlying database sequence. For example: any other application (that e.g. uses plain

Hibernate, @SequenceGenerator and allocationSize

一曲冷凌霜 提交于 2019-11-26 02:29:02
问题 We all know the default behaviour of Hibernate when using @SequenceGenerator - it increases real database sequence by one , multiple this value by 50 (default allocationSize value) - and then uses this value as entity ID. This is incorrect behaviour and conflicts with specification which says: allocationSize - (Optional) The amount to increment by when allocating sequence numbers from the sequence. To be clear: I do not bother about gaps between generated IDs. I care about IDs that are not

What's the Hi/Lo algorithm?

北城以北 提交于 2019-11-25 22:46:43
问题 What\'s the Hi/Lo algorithm? I\'ve found this in the NHibernate documentation (it\'s one method to generate unique keys, section 5.1.4.2), but I haven\'t found a good explanation of how it works. I know that Nhibernate handles it, and I don\'t need to know the inside, but I\'m just curious. 回答1: The basic idea is that you have two numbers to make up a primary key- a "high" number and a "low" number. A client can basically increment the "high" sequence, knowing that it can then safely generate