utilisateurs.java
package Model;
import Model.base.BaseUtilisateurs;
/**
* This is the object class that relates to the utilisateurs table.
* Any customizations belong here.
*/
public class Utilisateurs extends BaseUtilisateurs {
/*[CONSTRUCTOR MARKER BEGIN]*/
public Utilisateurs () {
super();
}
/**
* Constructor for primary key
*/
public Utilisateurs (java.lang.Integer _iduser) {
super(_iduser);
}
/**
* Constructor for required fields
*/
public Utilisateurs (
java.lang.Integer _iduser,
java.lang.String _password,
java.lang.String _nom,
java.lang.String _prenom,
java.lang.String _email,
java.lang.String _login) {
super (
_iduser,
_password,
_nom,
_prenom,
_email,
_login);
}
/*[CONSTRUCTOR MARKER END]*/
}
---
hibernateSessionFactory
package Model;
import Model.base.BaseUtilisateurs;
/**
* This is the object class that relates to the utilisateurs table.
* Any customizations belong here.
*/
public class Utilisateurs extends BaseUtilisateurs {
/*[CONSTRUCTOR MARKER BEGIN]*/
public Utilisateurs () {
super();
}
/**
* Constructor for primary key
*/
public Utilisateurs (java.lang.Integer _iduser) {
super(_iduser);
}
/**
* Constructor for required fields
*/
public Utilisateurs (
java.lang.Integer _iduser,
java.lang.String _password,
java.lang.String _nom,
java.lang.String _prenom,
java.lang.String _email,
java.lang.String _login) {
super (
_iduser,
_password,
_nom,
_prenom,
_email,
_login);
}
/*[CONSTRUCTOR MARKER END]*/
}
EtudiantDAO.java
---
package Model.dao;
import java.util.Iterator;
import java.util.List;
import net.sf.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import Model.Utilisateurs;
public class EtudiantDAO {
public static void main(String [] args) throws HibernateException{
Session session = (Session) HibernateSessionFactory.currentSession();
Transaction tx = session.beginTransaction();
//On insère 2 etudiant dans la BDD
Utilisateurs client = new Utilisateurs();
client.setIduser(12);
client.setPassword("root");
client.setNom("kete");
client.setPrenom("koli");
client.setEmail("@gmail.com");
client.setLogin("kolo");
client.setAdresse("rue 209");
client.setNewsletter(true);
client.setTel("0908PP8967") ;
client.setEmailsecours ("iouioui");
client.setVille ("rabat");
client.setNumappartement(12);
client.setTypeuser ("1");
client.setCodepostal("234");
client.setSexe("femme");
client.setQuartier ("ensi");
client.setInterphone ("13423") ;
session.save(client);
client = new Utilisateurs();
client.setIduser(12);
client.setPassword("root");
client.setNom("kete");
client.setPrenom("koli");
client.setEmail("@gmail.com");
client.setLogin("kolo");
client.setAdresse("rue 209");
client.setNewsletter(true);
client.setTel("0908PP8967") ;
client.setEmailsecours ("iouioui");
client.setVille ("rabat");
client.setNumappartement(12);
client.setTypeuser ("1");
client.setCodepostal("234");
client.setSexe("femme");
client.setQuartier ("ensi");
client.setInterphone ("13423") ;
session.save(client);
tx.commit();
List list = session.createQuery("from Etudiant").list();
Iterator it = list.iterator();
while(it.hasNext())
{
Utilisateurs e = (Utilisateurs)it.next();
System.out.println(e.getPrenom()+" "+ e.getNom());
}
HibernateSessionFactory.closeSession();
}
}
then I download apach-log4j-1.2.16 and communs-loggin and I put then into tomcate/lib
error testing are :
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Initial SessionFactory creation failed.org.hibernate.HibernateException: Could not instantiate dialect class
Exception in thread "main" java.lang.ExceptionInInitializerError
at Model.dao.HibernateSessionFactory.<clinit>(HibernateSessionFactory.java:22)
at Model.dao.EtudiantDAO.main(EtudiantDAO.java:15)
Caused by: 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:409)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:119)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2006)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1289)
at Model.dao.HibernateSessionFactory.<clinit>(HibernateSessionFactory.java:17)
... 1 more
Caused by: java.lang.ClassCastException: net.sf.hibernate.dialect.MySQLDialect cannot be cast to org.hibernate.dialect.Dialect
at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:78)
... 7 more