开发者

Running out of NHibernate HiLo-ids resulting in negative numbers

We're running an ASP.NET database application which uses HiLo to generate ids for entities. On top of this application, we have several websites using the same database. What we're seeing is that we run out of ids and the ID-column becomes a negative number.

We suspect this has something to do with the generator. As multiple websites run on top of the same codeb开发者_开发技巧ase and database and probably the HiLo algorithm quickly starts generating ids which are outside of the bigint-range (with quickly being relative of course).

Is it possible to configure the generator in such a way that it also uses the gaps (of which there are quite a few) in the Id-sequences, instead of bluntly increasing the value whenever it feels that's necessary?

Would that be a solution? Or should we be doing something else altogether?


what is your max_lo set to? The formula to generate id is as follows

h = high sequence (starting at 0) l_size = size of low block l = low sequence (starting at 1)

ID = h*l_size + l

Maybe your max_lo is set to high?


You can switch to Guid.Comb generator if this is possible or use int64 for ids. Take a look here for making final decision regarding what generator to use.


I've come across the same problem and also haven't been able to find a suitable answer.

We also have a site which is being ran as separate websites with each site in its own separate application pool, all on the same webserver.

Pragmatically, you'd be better off just switching to Identity mapping, if your databas supports it. It shouldn't be too hard to do, you should be able to modify your database schema with a bit of TSQL and the ID mappings with a bit of search/replace.

Do you have a concept similar to UoW in your application? Because a downside to identity generation is that it'll break the UoW (early inserts in order to get the identifier). It might be a price worth paying, though.

In my case the system could easily exist as a single site/app pool (it's multi-tenant on a single database, with single shared connection string, and is designed to run as a single instance on a webserver) so I'm going to test that before I make the jump to database-identities..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜