R – NHibernate HiLo – one table for all entities

nhibernate

I'm using NHibernate HiLo as my identity generator. I currently have a sepperate table in my database for each of my entity tables. For example I have Customer and CustomerKey table, each with a NextHiLo column.

What would be a great thing to have is a single table that holds key for all the others. Idealy would be if i could have a table like this:

TableName | NextHiLo
Customer | 19
Invoice | 5
Receipt | 3

If that isnt't possible with NHibernate, the next best thing would be:

CustomerHiLo | InvoiceHiLo | ReceiptHiLo
19 | 5 | 3

Is any of the two options above posible to achieve – the schema generation script produced by NHibernate doesn't apear to support any of them?

Best Answer

Have you tried using the where property of the hilo generator? Something like:

<class name="Customer">
    <id name="Id">
        <generator class="hilo">
            <param name="where">TableName = 'Customer'</param>
            ...
        </generator>
    </id>
    ...
</class>
Related Topic