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:
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
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] <%X{auth}> - %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>
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 <?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>
Lors de l'exécution, le programme se plante sur la ligne Configuration cfg = new Configuration();
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();
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 !
Partager