8

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?

Miha Necak
  • 81
  • 1
  • 4
  • I know this question is old, but how did you resolve this? I'm trying to resolve the same issue. I've tried your first approach with only 2 columns, but it seems my ids are continous over multiple tables. – Prabu Jan 24 '13 at 00:35

3 Answers3

12

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>
Fredy Treboux
  • 3,167
  • 2
  • 26
  • 32
2

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

Ufuk Hacıoğulları
  • 37,978
  • 12
  • 114
  • 156
mcintyre321
  • 12,996
  • 8
  • 66
  • 103
2

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

Daniel
  • 8,133
  • 5
  • 36
  • 51