views:

155

answers:

1

Hi,

I have two databases. One from Oracle 10g. Another from Mysql. I have configured my web application with Nhibernate for Oracle and now I am in need of using the MySQL database. So how can i configure the hibernate.cfg.xml so that i can use both of the database at the same application?

My current hibernate.cfg.xml is:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="connection.driver_class">NHibernate.Driver.OracleClientDriver</property>
    <property name="connection.connection_string">Data Source=xe;Persist Security Info=True;User ID=hr;Password=hr;Unicode=True</property>
    <property name="show_sql">false</property>
    <property name="dialect">NHibernate.Dialect.Oracle9Dialect</property>
    <!-- mapping files -->
    <mapping assembly="DataTransfer" />
  </session-factory>
</hibernate-configuration> 
+3  A: 

You can check "Burrow" addin for nhibernate

http://nhforge.org/wikis/burrow/introduction.aspx

Multiple databases support. multiple databases becomes easy, you don't need a SessionFactoryPath, you simply give Burrow an entity type, and Burrow will find the right ISession for you. If you are using GenericDAO, the multiple DB support can be very transparent - your code does not need to know there are multiple databases.

Seems that you could also use unhaddins, haven't used it and I didn't find the documentation. http://code.google.com/p/unhaddins/

I had to do that many time ago I followed this article, it's a more complex solution but I paste it just in case.

http://www.codeproject.com/KB/aspnet/NHibernateMultipleDBs.aspx

Claudio Redi
I've used Burrow successfully with multiple databases, but it doesn't seem to be actively maintained, so I would use another solution if possible.
Stuart Ellis