Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate HiLo - one table for all entities

Tags:

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?

like image 457
Miha Necak Avatar asked Aug 31 '09 09:08

Miha Necak


3 Answers

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>
like image 117
Fredy Treboux Avatar answered Jan 24 '23 11:01

Fredy Treboux


I have written about this here: http://daniel.wertheim.se/2011/03/08/nhibernate-custom-id-generator/

like image 31
Daniel Avatar answered Jan 24 '23 11:01

Daniel


there is a patch for adding this on JIRA, but I don't know when it will be in the trunk https://nhibernate.jira.com/browse/NH-1374

like image 29
mcintyre321 Avatar answered Jan 24 '23 12:01

mcintyre321