IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

NHibernate Discussion :

[nHibernate - VS2005]


Sujet :

NHibernate

  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    4
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Mars 2007
    Messages : 4
    Points : 5
    Points
    5
    Par défaut [nHibernate - VS2005]
    Bonjour !

    Ca fait quelques jours que je cherche, lis des tutos sur le net sans jamais comprendre pourquoi ça ne marche pas. Si vous pouviez m'aider, ce serait sympa.
    J'essaye donc de faire tourner un simple exemple nHibernate sous VS2005.
    Dans mon projet, 3 fichiers importants:
    • App.config
    • hibernate.cfg.xml
    • Personne.hbm.xml (mapping de l'objet DB)


    App.config:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <configSections>
        <section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
      </configSections>
     
      <nhibernate>
        <add key="hibernate.show_sql" value="true" />
        <add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />
        <add key="hibernate.dialect"                      value="NHibernate.Dialect.MsSql2000Dialect" />
       <add key="hibernate.connection.driver_class"          value="NHibernate.Driver.SqlClientDriver" />
       <add key="hibernate.connection.connection_string" value="Server=localhost;initial catalog=nhibernate;Integrated Security=SSPI" 	/>
      </nhibernate>
     
      <!-- This section contains the log4net configuration settings -->
      <log4net>
     
        <!-- Define some output appenders -->
     
        <appender name="rollingFile" type="log4net.Appender.RollingFileAppender,log4net" >
     
          <param name="File" value="log.txt" />
          <param name="AppendToFile" value="true" />
          <param name="RollingStyle" value="Date" />
          <param name="DatePattern" value="yyyy.MM.dd" />
          <param name="StaticLogFileName" value="true" />
     
          <layout type="log4net.Layout.PatternLayout,log4net">
            <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &lt;%X{auth}&gt; - %m%n" />
          </layout>
        </appender>
     
        <!-- Setup the root category, add the appenders and set the default priority -->
     
        <root>
          <priority value="ALL" />
          <appender-ref ref="rollingFile" />
        </root>
     
      </log4net>
     
     
    </configuration>
    hibernate.cfg.xml
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    <?xml version="1.0" encoding="utf-8" ?>
    <hibernate-configuration  xmlns="urn:nhibernate-configuration-2.0" >
      <session-factory name="nHibernateTest">
        <!-- properties -->
        <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
        <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
        <property name="connection.connection_string">Server=localhost;initial catalog=TestDD1;Integrated Security=SSPI</property>
        <property name="show_sql">false</property>
        <property name="dialect">NHibernate.Dialect.MsSql2000Dialect</property>
        <property name="use_outer_join">true</property>
        <property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
        <!-- mapping files -->
        <mapping assembly="nHibernateTest" />
      </session-factory>
     
    </hibernate-configuration>
    Pour ce qui est de l'appel à nHibernate:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    Configuration cfg = new Configuration();
                cfg.AddAssembly("nHibernateTest");
                ISessionFactory factory = cfg.BuildSessionFactory();
                ISession session = factory.OpenSession();
                ITransaction transaction = session.BeginTransaction();
     
                Personne newPers = new Personne();
                newPers.IdPersonne = 123;
                newPers.NomPersonne = "Smith";
                newPers.PrenomPersonne = "John";
     
                // Tell NHibernate that this object should be saved
                session.Save(newPers);
     
                // commit all of the changes to the DB and close the ISession
                transaction.Commit();
                session.Close();
    Lors de l'exécution, le programme se plante sur la ligne Configuration cfg = new Configuration();
    Exception: The dialect was not set. Set the property hibernate.dialect.

    J'ai donc l'impression qu'il ne prend pas en compte mes fichiers de paramètres

    Quelqu'un aurait une idée ?

    D'avance merci !

  2. #2
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    4
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Mars 2007
    Messages : 4
    Points : 5
    Points
    5
    Par défaut
    Pour ceux que ça intéresse (ou qui seraient bloqués comme moi), avec le code suivant, on avance un peu plus loin

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Configuration cfg = new Configuration();
    cfg.Configure();
    cfg.AddAssembly("nHibernateTest");

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [VS2005][UML]Nhibernate et MagicDraw AdroMDA
    Par bartoumi dans le forum NHibernate
    Réponses: 1
    Dernier message: 25/01/2007, 07h07
  2. [VS2005][VB.Net] Custom Format dans un DataGridView
    Par Vonotar dans le forum VB.NET
    Réponses: 10
    Dernier message: 22/11/2005, 08h15
  3. Réponses: 5
    Dernier message: 13/11/2005, 19h10
  4. [VS2005][C#] Delete sur un Dataset typé
    Par Xno dans le forum Windows Forms
    Réponses: 3
    Dernier message: 19/09/2005, 18h13

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo