Bonjour,
J'ai l'erreur suivante
Et voici le code que je utilise :log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.hibernate.HibernateException: Could not instantiate dialect class
at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:84)
at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:42)
at org.hibernate.cfg.SettingsFactory.determineDialect(SettingsFactory.java:422)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:128)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
at com.caciopee.controllers.TestConnection.main(TestConnection.java:21)
Caused by: java.lang.ClassCastException: net.sf.hibernate.dialect.postgreSQLDialect cannot be cast to org.hibernate.dialect.Dialect
at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:78)
... 6 more
Mon code sous 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 import org.hibernate.Session; import org.hibernate.Query; import org.hibernate.cfg.Configuration; import net.sf.hibernate.dialect.postgreSQLDialect; import org.hibernate.dialect.*; import com.caciopee.entities.Users; public class TestConnection{ public static void main(String args[]) throws Exception { SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); Session session = sessionFactory.openSession(); try { Query query = session.createQuery("Select * from users"); query.setString("username", "password"); Iterator personnes = query.iterate(); while (personnes.hasNext()) { Users user = (Users) Users.next(); System.out.println("bien joue ! "); } } finally { session.close(); } sessionFactory.close(); } }
Quelqu'un saurait-il m'indiquer d'où peut venir le problème ?
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 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.connection.driver_class">org.postgresql.Driver</property> <property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property> <property name="hibernate.connection.username">postgres</property> <property name="hibernate.connection.password">iman</property> <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/location-voiture</property> <property name="dialect">net.sf.hibernate.dialect.postgreSQLDialect</property> <property name="hibernate.dialect">net.sf.hibernate.dialect.postgreSQLDialect</property> <mapping resource="com/caciopee/entities/Users.hbm.xml"/> </session-factory> </hibernate-configuration>
Merci d'avance pour votre aide.
Partager