I don't think you need to inject into the NHibernate process or some kind of intercetor. I think it's good to do it in your code, be sure to make your code has it's own class with a static method (which query the database for the next id). Another option, you can try implement your own custom NHibernate generator, but I don't know if you can use it without being a primary key.
A quick search on Google: http://www.lucisferre.org/coding/index.php/2009/07/13/implementing-a-custom-id-generator-for-nhibernate-1 Sincerely, William Chang On Aug 28, 10:36 am, "Mauro Servienti" <[email protected]> wrote: > Hi all, > > I'm using NH to map a domain that contains some entities that have an > "identification number", it is not a primary key, it's just an id number > that has a meaning for the user. A really simple example is the invoice > number. > > The important thing is that this id number is always generated and never > assigned by the user. Each entity has its own strategy to generate this "id > number" that has to be generated only at insert time and then is immutable, > which is the best strategy to inject in NH this generation logic? Is an > IInterceptor a viable way? > > The simplest generation strategy, just for the records, is the "invoice > number": > > - Within a transaction. > > - Just before insert a transient invoice look into invoices table > sorting invoices by number descending and filtering by incoming document > year; > > - Take the top number + 1 if one, otherwise take 1; > > - Assign it to the invoice entity; > > - Commit transaction; > > I know that I can do all this in my code but I would like to automate the > process at the persistence level. > > TIA, best regards. > > .m --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nhusers?hl=en -~----------~----~----~----~------~----~------~--~---
