fluent-nhibernatehilo

Fluent NHibernate — class/entity specific next_hi seeds when using HiLo generator


Basically I'm trying to do the same thing as this question but with Fluent NHibernate.

Here is my id generation convention:

    public class IdGenerationConvention : IIdConvention
    {
            public void Apply(IIdentityInstance instance)
            {
                    instance.GeneratedBy.HiLo("1000");
            }
    }

Now this works great, but all classes end up using the same next_hi.

    create table hibernate_unique_key (
            next_hi INTEGER 
    )

Does anyone know how to specify that each class should use it's own next_hi?

To clarify, I'd like to end up with something like customer_next_hi and order_next_hi, assuming it works based on columns. If it's row based then that's fine too, provided each entity knows which row to use for it's next_hi value.


Solution

  • I also asked this question in the Fluent NHibernate Google Group and it appears that the only way to do this would be to create a custom id generator class that either inherits from HiLo or TableGenerator. From what I gather, the key issue is that the SQL statement to create the seed table is only executed once, and there isn't a built-in override or hook to get it to create entity specific columns or rows.

    So something along the lines of this is what I'll need to do. I'll post more once I have a working implementation.