Hibernate Dialect must be explicitly set
Bonjour , novice dans l'utilisation de Hibernate .
J'obtiens une erreur Hibernate Dialect must be explicitly set.
Voici l'erreur complète:
Code:
1 2 3 4 5 6 7 8
| Exception in thread "main" org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
at org.hibernate.dialect.DialectFactory.determineDialect(DialectFactory.java:57)
at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:39)
at org.hibernate.cfg.SettingsFactory.determineDialect(SettingsFactory.java:426)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:128)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2073)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1298)
at test.TestHibernate3.main(TestHibernate3.java:17) |
Lors de l'appel du code suivant:
Code:
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
|
package test;
import mywebapp.bean.data.Article;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
public class TestHibernate1 {
public static void main(String args[]) throws Exception {
Configuration config = new Configuration();
config.addClass(Article.class);
SessionFactory sessionFactory = config.buildSessionFactory();
Session session = sessionFactory.openSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
Article article = new Article("6","Montre");
session.save(article);
session.flush() ;
tx.commit();
} catch (Exception e) {
if (tx != null) {
tx.rollback();
}
throw e;
} finally {
session.close();
}
sessionFactory.close();
}
} |
Je suppose que c'est peut etre le fichier de config qui porte un problème:
Code:
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
| <?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="connection.url">jdbc:mysql://localhost/test</property>
<property name="connection.username">root</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.password"></property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<!-- thread is the short name for
org.hibernate.context.ThreadLocalSessionContext
and let Hibernate bind the session automatically to the thread
-->
<property name="current_session_context_class">thread</property>
<!-- this will show us all sql statements -->
<property name="hibernate.show_sql">true</property>
<!-- mapping files -->
<mapping resource="mywebapp/persistance/data/Article.hbm.xml" />
<mapping resource="mywebapp/persistance/data/Panier.hbm.xml" />
</session-factory>
</hibernate-configuration> |
Avec Article.hbm.xml
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| <?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="Article" table="article">
<id name="reference" type="string" />
<property name="nom" type="string" not-null="true" />
</class>
</hibernate-mapping> |
et Panier.hbm.xml
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| <?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="Panier" table="panier">
<id></id>
<property name="quantite" type="int" not-null="true" />
<property name="reference" type="string" not-null="true" />
</class>
</hibernate-mapping> |
La connexion à la base de données est bien configurée...
Comment résoudre le problème ?
merci