3

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> 
skaffman
  • 398,947
  • 96
  • 818
  • 769
Flint
  • 63
  • 3

2 Answers2

2

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
  • 67,454
  • 15
  • 130
  • 155
  • 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 Apr 17 '10 at 15:49
0

Here may be a simpler solution. It provides a new feature that allows the hibernate-configuration to have multiple session-factory elements by giving them names, and extends the NHibernate.Cfg.Configuration.Configure to accept a sessionFactoryName.

Configure NHibernate hibernate.cfg.xml file to have more connection strings

Community
  • 1
  • 1
roydukkey
  • 3,149
  • 2
  • 27
  • 43