NHibernate - Banco de dados Suportados pelo NHibernate


Atualmente os principais banco de dados suportados pelo NHibernate são:

Com base nisso segue uma tabela contendo o código para o arquivo de configuração do NHibernate usado para cada um destes bancos de dados.

O arquivo de configuração define as informações do provedor, dialeto, driver e string de conexão do banco de dados usado para persistência.

Lembrando que podemos realizar esta definição no arquivo de configuração da aplicação (app.config ou web.config) ou no arquivo NHibernate.cfg.xml;

Obs: A sintaxe usada nas configurações referem-se a versão 2.1.2 do NHibernate e não devem ser usadas em versões anteriores.

SQL Server
<?xml version="1.0" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
    <session-factory>
        <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
        <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
        <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
        <property name="connection.connection_string">Server=(local);Initial Catalog=dbname;User Id=user;Password=********</property>
    </session-factory>
</hibernate-configuration>
Microsoft Access
<?xml version="1.0" ?>
<hibernate-configuration  xmlns="urn:nhibernate-configuration-2.2" >
    <session-factory>
        <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
        <property name="dialect">NHibernate.JetDriver.JetDialect, NHibernate.JetDriver</property>
        <property name="connection.driver_class">NHibernate.JetDriver.JetDriver, NHibernate.JetDriver</property>
        <property name="connection.connection_string">Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Teste.mdb</property>
    </session-factory>
</hibernate-configuration>
Firebird
<hibernate-configuration  xmlns="urn:nhibernate-configuration-2.2" >
    <session-factory name="NHibernate.Test">
        <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
        <property name="connection.driver_class">NHibernate.Driver.FirebirdClientDriver</property>
        <property name="connection.isolation">ReadCommitted</property>
        <property name="connection.connection_string">
            Server=localhost;
            Database=C:\nhibernate.fdb;
            User=SYSDBA;Password=masterkey
        </property>
        <property name="show_sql">false</property>
        <property name="dialect">NHibernate.Dialect.FirebirdDialect</property>
        <property name="use_outer_join">true</property>
        <property name="command_timeout">444</property>
        <property name="query.substitutions">true 1, false 0, yes 1, no 0</property>
    </session-factory>
</hibernate-configuration>
PostgreSQL
<?xml version="1.0" encoding="utf-8"?>
<hibernate-configuration  xmlns="urn:nhibernate-configuration-2.2" >
    <session-factory name="NHibernate.Test">
        <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
        <property name="connection.driver_class">NHibernate.Driver.NpgsqlDriver</property>
        <property name="connection.connection_string">
            Server=localhost;initial catalog=nhibernate;User ID=nhibernate;Password=********;
        </property>
        <property name="dialect">NHibernate.Dialect.PostgreSQLDialect</property>
    </session-factory>
</hibernate-configuration>
DB2UDB
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.0" >

    <session-factory name="session">
        <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
        <property name="connection.driver_class">NHibernate.Driver.OdbcDriver</property>
        <property name="connection.connection_string">driver={IBM DB2 ODBC DRIVER};Database=db;hostname=host;port=port;protocol=TCPIP; uid=uid; pwd=pwd</property>
        <property name="show_sql">true</property>
        <property name="dialect">NHibernate.Dialect.DB2Dialect</property>
        <property name="use_outer_join">true</property>
        <mapping resource="..." />
        </session-factory>
</hibernate-configuration>
MySQL
<?xml version="1.0" encoding="utf-8"?>
<hibernate-configuration  xmlns="urn:nhibernate-configuration-2.2" >
    <session-factory name="NHibernate.Test">
        <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
        <property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
        <property name="connection.connection_string">
            Database=test;Data Source=localhost;User Id=blah;Password=blah
        </property>
        <property name="dialect">NHibernate.Dialect.MySQLDialect</property>
    </session-factory>
</hibernate-configuration>
SQLite
<?xml version="1.0" encoding="utf-8"?>
<hibernate-configuration  xmlns="urn:nhibernate-configuration-2.2" >
    <session-factory name="NHibernate.Test">
        <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
        <property name="connection.driver_class">NHibernate.Driver.SQLiteDriver</property>
        <property name="connection.connection_string">
            Data Source=nhibernate.db;Version=3
        </property>
        <property name="dialect">NHibernate.Dialect.SQLiteDialect</property>
        <property name="query.substitutions">true=1;false=0</property>
    </session-factory>
</hibernate-configuration>

Obs: Atente para o fato que você deverá alterar a string de conexão usada nos exemplos acima.

Recentemente foi lançado o NHibernate 3.1.0 veja detalhes em : http://nhforge.org/Default.aspx

Eu sei é apenas NHibernate, mas eu gosto...

Referências:

José Carlos Macoratti