When using the HiLo ID generation strategy, what types should be used to store IDs?

I'm asking this from a C # / NHibnernate perspective, but it's generally applicable. The problem is that the HiLo strategy goes pretty fast and, for example, a table with low record counts (such as users) shares with the same set of ids as a table with high record rates (eg comments). Thus, you can get higher numbers faster than other strategies. So what do people recommend?

Code side: INT / UINT / LONG / ULONG?

DBSide: INT / BIGINT?

My feeling is to go with long and large figures, but would like to test common sense :)

+2


a source to share


2 answers


Complementing Diego's answer.

You can set a parameter table

for each generator, but IMO this leads to unnecessary number of tables just for storing IDs.

I would recommend using one row per object (in the same table). With advanced options, you can customize the HiLo algorithm and lock only the line you want. You have separate seeds for each entity. In FluentNH it will be something similar to:

        Id(x => x.Id, "Id")
            .GeneratedBy.HiLo("IdsTable", "id", "20", 
                p => p.AddParam("where", "table = 'mappedent'"));

      



Regardless, you can also avoid the extra parameter where

and just set a different column (which allows you to have different types of IDs even in the DB). However, it bothers you if you have a large number of objects (due to a constraint on a DB column). Also, remember that every object that requests a range of identifiers will block all others, which can lead to deadlocks in some situations.

Hope this helps!

Hello,

Philip

+5


a source


You are probably durable.



In any case, you don't need to use the same table for all objects. You can set the parameter table

for each generator to a different value.

+2


a source







All Articles