views:

36

answers:

1

Hi all,

So I'm currently attempting to do a promotion of objects from one database to another in my app. Basically I want to allow the user to click a button and promote changes from staging to production, as it were.

To do this, I really want to keep the IDs the same in order to help with debugging. So for example if the object has an ID of 6 in the staging db, I want it to have that same ID on production. To do this, we turned off identity on our production db and just made those primary key columns with non-null integers.

In my staging mapping file, my IDs are mapped using the "identity" generator, but for production I want them to be "assigned". Is it possible to programmatically change this, perhaps using an interceptor or something similar?

Thanks in advance!

A: 

I'm not a sure I understand your question fully, but it looks to me that you are trying to use the same NHibernate session to address the two environments? To accomplish your goals, you are looking for ways to substitute the id generator before you save to production?

If this is the case, you shouldn't! On the contrary, you should choose a strategy that uses two different NHibernate sessions, that is, a session per environment.

So basically you should fetch the objects you want to promote from the staging environment in the session that is configured with a mapping with an identity generator, and translate these objects into object instances attached to a session that is configured with a mapping with an assigned generator type.

Makes any sense?

sergevm

related questions