Hi all,
I've been battling with this issue for days now, and thought I'd post a message here to see if anyone else has ever come into contact with this before and might know a few useful tips.
Basically, I want to be able to map a single object to several tables over multiple databases.
At the moment, I'm creating a new session factory for each Configuration object I've got (one for each configuration file and it's mapping file that's passed in via e.g. dependency injection). This approach works fine, and I've wrapped the sessions CRUD operations in a a transaction scope so they all enlist in the DTC. This means I can create a new object and save it, and it gets saved to all tables I've specified.
The real headscratcher here is what to do about the Id. As I use surrogate keys, I'm having a real hard time figuring out how to squeeze all the primary keys (and foreign keys) from my tables into my one object. I've tried using <composite-id>, <id-bag> and my own IUserType type but to no avail. I'd love it if there was a way to tell nHibernate to put the id in some sort of Dictionary and use either a specified key or the sessionId to set and get it.
I suppose one could use a global key (such as a guid) but I'd rather not for now, as the additional tables are mainly legacy tables that I wouldn't like to fiddle too much with.
Has anyone ever encountered this kind of scenario before?? Sorry for the long post.
Cheers,
Fred
|