1
resposta

Configurar NHibernate - PostgreSQL

Bom dia,

Gostaria de saber se alguém realizou a configuração do NHibernate utilizando o PostgreSQL? Se possível poderiam me passar uma orientação ou tutorial de como faze-lo.

Obrigado, Lucas Estéfano.

1 resposta

Olá, Lucas

Um outro aluno (Vinicius Henrique) conseguiu usar NHibernate com PostgreSQL. Veja por favor a configuração que ele usou:

https://cursos.alura.com.br/forum/topico-postgresql-exception-could-not-compile-the-mapping-document-lojanhibernate-mapeamento-usuario-hbm-xml-nhibernate-mappingexception-45048

Produto.hbm.cfg

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:hibernate-mapping-2.2"
                   assembly="Loja"
                   namespace="Loja.Entidades">
      <class name="Usuario">
      <id name="Id">
        <generator class="identity"></generator>
      </id>
      <property name="Nome"/>
    </class>

</hibernate-mapping>

hibernate.cfg.xml

<?xml version="1.0" encoding="utf-8" ?>

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">

  <session-factory>
    <property name="connection.driver_class">
      NHibernate.Driver.NpgsqlDriver
    </property>
    <property name="connection.provider">
      NHibernate.Connection.DriverConnectionProvider
    </property>    
    <property name="dialect">
      NHibernate.Dialect.PostgreSQL82Dialect
    </property>
    <property name="connection.connection_string">
      Server=127.0.0.1;Port=5432;User ID=postgres;Password=xxxx;Database=Loja
    </property>
    <property name="show_sql">
      true
    </property>
  </session-factory>
</hibernate-configuration>

Usuario.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LojaNHibernate.Entidade
{
    public class Usuario
    {
        public virtual int Id { get; set; }
        public virtual string Nome { get; set; }

    }
}

Obs.: encontrei um outro tutorial sobre Postgre com NHibernate, só que mais detalhado:

http://www.veereshr.com/DotNet/NHibernateSetup

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software