saurabhs_iitk wrote:
The problem is that when second object is inserted it gives the error "a different object with the same identifier value was already associated with the session: 0, of class:"
But i have to insert them in one transaction.
Others may have a better solution for you, and I agree with Adam that seeing your mappings/classes would help, but if you get no love from other quarters, try this:
Create a util class global that provides a decrementing value, from -1. It only needs to be process local, but it certainly should be threadsafe. Not too bad, since you should be able to use interlocked decrement instead of full-on monitors ( lock ( object ) {...} ).
Now, in your child class ctor, assign the identifier value from this global instead of defaulting it to 0.
You will probably need an unsaved-value for SaveOrUpdate so cascades will be supportable (handy for P-C) so add a version column to your table/mapping/class, and use the unsaved-value there.
Ugly? Kinda, but it should solve your problem in lieu of an actual, you know, solution.