-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Multiple mappings for a single object
PostPosted: Thu Nov 15, 2007 5:29 pm 
Newbie

Joined: Thu Nov 15, 2007 5:06 pm
Posts: 5
I know storing data in multiple places might be regarded as bad design, but I have no choice in the matter. In some cases, I have multiple databases, which have very similar tables and I want to store data in these tables. Note that I am only reading from one table though.

I also know that using multiple databases with NHibernate is possible with multiple session factories. But I haven't seen anything about different mappings for these databases.

If an entity is attached to one session, is it possible to save it to another?


Top
 Profile  
 
 Post subject: RE: Multiple mappings for a single object
PostPosted: Fri Nov 16, 2007 5:20 am 
Newbie

Joined: Tue Jan 09, 2007 5:24 am
Posts: 15
Hi - I haven't tried using multiple session factories, but it is fairly simple to work against multiple databases as long as these are on the same database server, in which case you don't need multiple session factories.

I don't know if your problem fits into that category, but here is some information:

1) Connect to the database with a connection string that gives access to all the databases that you require.

2) In the mapping document for your classes you set the "schema" property to the database that you want to use. For instance if class C1 is in database DB1 and class C2 is in DB2, set the schema to "DB1.dbo" for C1 and "DB2.dbo" for C2.

3) If you have a default schema, for most of your tables you can specify that in your NHibernate setup parameters, and then override the schema property of the classes that does not lie within the the default schema.

Check this resource for more information:
http://www.codeproject.com/useritems/NH ... x1915287xx

Hope this helps

Cheers,
Thomas


Top
 Profile  
 
 Post subject: Re: RE: Multiple mappings for a single object
PostPosted: Fri Nov 16, 2007 11:18 am 
Newbie

Joined: Thu Nov 15, 2007 5:06 pm
Posts: 5
Unfortunately the database servers are completely separate. In fact they are different engines, so simply changing the schema won't work.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 16, 2007 11:56 am 
Regular
Regular

Joined: Wed Aug 15, 2007 7:37 am
Posts: 73
You can set up different sessions with different settings and mapping schema (I only managed to do so in code rather than a config file). Loading and saving across sessions is something I've done with varying degrees of success - in particular, collections can only be in one active session at once, and I've had problems where the second session runs updates rather than inserts.

I can't find the code I used right now, but digging around on Google should help.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.