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
Hi Tuna,
so you suggest to, for example, inherit from DefaultSaveEventListener and override the PerformSaveOrUpdate and here do what I need to do.
Is it correct?
.m
Hi Fabio,
Yes, you get it, but not only. We have several document types, other then invoices and “bolle” such as customer account statements or a document protocol system (I don’t know how to call in English in Italian is “protocollo”) and every “document” type has its own id generation logic.
.m
From: nhu...@googlegroups.com [mailto:nhu...@googlegroups.com] On Behalf Of Fabio Maulo
Sent: venerdì 28 agosto 2009 23:28
To: nhu...@googlegroups.com
Subject: [nhusers] Re: Document number generation
Is it for Italian invoice numbers ?