-->
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.  [ 3 posts ] 
Author Message
 Post subject: How to Use two different database (with each a dialect) at t
PostPosted: Fri Nov 10, 2006 4:17 am 
Newbie

Joined: Fri Nov 03, 2006 4:09 am
Posts: 4
Hello,

At the moment we are using a Informix database(1), at the same time I want to use a access database(2) within the same ASP.Net(C#) 2005 project. In (2) it's easier to create a new table etc so it's ideal for testing things. My questions are:

a) Can I use two different databases (with different dialects) at the same time?;
b) If yes: how about configuration sections in my Web.Config (<session-factory> section)
c) if a & b are no problem : I'll propably need a extra property in my ...hbm.xml files to stear witch configuration(dialect) loads each ...hbm.xml file. Does anybody know answers to these question's?

If it is possible I will write a small 'How to' document to share the knowledge because I couldn't find anything on the subject.

Kind regards,

Stefan


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 10, 2006 6:10 am 
Beginner
Beginner

Joined: Fri Oct 20, 2006 8:02 am
Posts: 36
Hi. I don't know how to do this using a configuration file.

If you make your configuration programatically it is simple.

But you will have two configurations, and you will have two sessions one for each configuration.

something like this:

Code:
Configuration cfg1 = new Configuration();
cfg1.SetProperty(NHibernate.Cfg.Environment.ConnectionProvider,"NHibernate.Connection.DriverConnectionProvider");
cfg1.SetProperty(NHibernate.Cfg.Environment.Dialect,"NHibernate.Dialect.FirebirdDialect");
cfg1.SetProperty(NHibernate.Cfg.Environment.ConnectionDriver,"NHibernate.Driver.FirebirdDriver");
cfg1.SetProperty(NHibernate.Cfg.Environment.QuerySubstitutions,"your substitutions");
cfg1.SetProperty(NHibernate.Cfg.Environment.ConnectionString,"conection string 1");

... add your mapping files to cfg1 ...

Configuration cfg2 = new Configuration();
cfg2.SetProperty(NHibernate.Cfg.Environment.ConnectionProvider,"NHibernate.Connection.DriverConnectionProvider");
cfg2.SetProperty(NHibernate.Cfg.Environment.Dialect,"NHibernate.Dialect.MySQLDialect");
cfg2.SetProperty(NHibernate.Cfg.Environment.ConnectionDriver,"NHibernate.Driver.MySQLDriver");
cfg2.SetProperty(NHibernate.Cfg.Environment.QuerySubstitutions,"your substitutions");
cfg2.SetProperty(NHibernate.Cfg.Environment.ConnectionString,"conection string 2");

... add your mapping files to cfg2 ...

ISession session1 = cfg1.BuildSessionFactory().OpenSession();
ISession session2 = cfg2.BuildSessionFactory().OpenSession();


And then you can use witch one you wants.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 10, 2006 12:51 pm 
Beginner
Beginner

Joined: Fri Sep 02, 2005 12:13 pm
Posts: 44
Location: Denver, CO
I've written an article on CodeProject.com concerning this subject: http://www.codeproject.com/useritems/NH ... pleDBs.asp . The approach I suggest will work cleanly with completely different databases, as you're requesting. I've been using this exact approach on my current, three-database project and it's been working very well. (Two of the databases require open-in-session transactions while the third is a read-only, no-transaction communication channel.) It's a little tricky to set up initially, but once it's in place, you'll never think about it again.

Let me know if you use it as I'm always interested in feedback, good or bad!

Billy


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.