2010-04-16 50 views
3

我有兩個數據庫。一個來自Oracle 10g。另一個來自Mysql。我已經使用Nhibernate for Oracle配置了我的Web應用程序,現在我需要使用MySQL數據庫。那麼我怎樣才能配置hibernate.cfg.xml,以便我可以在同一個應用程序中使用兩個數據庫?與NHibernate的多個數據庫

我目前的hibernate.cfg.xml是:

<?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> 

回答

2

您可以檢查 「地洞」 插件爲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.

看來,你也可以使用unhaddins ,沒有使用它,我沒有找到文檔。 http://code.google.com/p/unhaddins/

我不得不這樣做很多次前我跟着這篇文章,這是一個更復雜的解決方案,但我粘貼它,以防萬一。

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

+0

我用挖洞成功地與多個數據庫,但它似乎並沒有得到積極的維護,所以如果可能的話,我會用另一種解決方案。 – 2010-04-17 15:49:51

相關問題