4

We have a fairly robust system using NHibernate, we're in the middle of migrating from a single database server to having two servers, one for administration and one for our public facing web site. This is mainly so that we can do things like content management with workflow that won’t affect the current site. As of today, they are two databases in the same server, but over time I can see using two physical machines with a web service call to push data.

So as an example, one of our marketing guys decides to introduce a new promotion through the admin , and schedule it for 2 weeks from now. We are working on a scheduling system that would push the new promotion to our production server when it’s kicked off. The intent was to use the same NHibernate providers for the data pushes, but we need to maintain referential integrity.

We’re using fluent nhibernate, and I can see writing two different class maps, and then using a some form of dependency injection ( IE structure map) of choosing which map to load. I was hoping for a better answer as that seems impossible to maintain as the system grows. Any suggestions?

jcavaliere
  • 125
  • 1
  • 1
  • 8
  • And exactly what is your question? You want to use the same ID on both servers? – BennyM Nov 08 '09 at 15:25
  • That’s correct. I’ve written come tests on various methods on the ISession - Replicate, Merge, SaveOrUpdate, SaveOrUpdateCopy. All of these will either throw an error generate a new ID instead of using the current ID. I saw the method CurrentSession().Replicate(entity,ReplicationMode.Overwrite); - it looked the most promising. Is this possibly a bug? – jcavaliere Nov 08 '09 at 15:46
  • Are you using db generated id's? – BennyM Nov 08 '09 at 18:34
  • Yes, we have load balanced servers running the NHibernate code, and the only logical place to have it generated in the DB at the time. I’m open to suggestions, but the idea of a custom ID generator in code brings up questions about data corruption if it ever got out of sync between app servers. – jcavaliere Nov 08 '09 at 20:32

1 Answers1

4

ISession.Replicate is not supported with DB generated ID values. As illustrated by this issue in the NHibernate issue tracker.

  • I suggest either to use your own ID generator or Guid/Guid.Comb since you'll be able to use NHibernate's replication in that case (as explained in the issue)
  • You can also write your own replication code which does not use NHibernate, if it's simple enough this is doable.
  • Use replication technology that your DB supports. I've used replication between MS SQL Servers before, and it's not that hard to set up. I'm quite sure other RDBMS's support similar stuff.
BennyM
  • 2,796
  • 16
  • 24