简体   繁体   中英

nHibernate synchronize two databases

I have two databases with the same structure on different servers and have to synchronize them bidirectionally. In databese 1 need to send sales information in database 2 need to send information from entries. I need to make this sync with nhibernate because the system can be used with any database: postgreSQL, mysql, oracle, sqlserver, etc..

What is the best strategy to make this application?

Seems like you need to figure out a couple of things:

  1. Spin up session factories for the two databases you need to sync
  2. Identify objects that need to be synchronized
  3. Sync them with the merge command

ISession.Merge()

  • if there is a persistent instance with the same identifier currently associated with the session, copy the state of the given object onto the persistent instance
  • if there is no persistent instance currently associated with the session, try to load it from the database, or create a new persistent instance
  • the persistent instance is returned
  • the given instance does not become associated with the session, it remains detached

We actually do something similar when we archive data between databases. The trickiest part for you may be identifying what needs to by synced.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM