Erreur "Could not find a getter"
Bonjour,
Dans mon projet web dynamique avec Hibernate et MySQL, j'ai une erreur qui m'indique que le getter de id-ecole n'est pas trouvé alors qu'il est bien crée dans la classe bean.
Je compile GestionEcole.java comme application java j'obtiens :
Erreur :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| Exception in thread "main" java.lang.ExceptionInInitializerError
at essai1.GestionEcole.ajouterEcole(GestionEcole.java:11)
at essai1.GestionEcole.main(GestionEcole.java:22)
Caused by: org.hibernate.PropertyNotFoundException: Could not find a getter for id_ecole in class essai1.ecole
at org.hibernate.property.BasicPropertyAccessor.createGetter(BasicPropertyAccessor.java:306)
at org.hibernate.property.BasicPropertyAccessor.getGetter(BasicPropertyAccessor.java:299)
at org.hibernate.tuple.PropertyFactory.getGetter(PropertyFactory.java:191)
at org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyFactory.java:67)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:147)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:457)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:131)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:84)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:261)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1327)
at util.HibernateUtil.<clinit>(HibernateUtil.java:8)
... 2 more |
voila mon code:
code src/essai1/ecole.java
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| package essai1;
public class ecole {
private int id_ecole;
private String nom_ecole;
public int getIdEcole() {
return id_ecole;
}
public void setIdEcole(int id) {
this.id_ecole = id;
}
public String getNomEcole() {
return nom_ecole;
}
public void setNomEcole(String nom) {
this.nom_ecole = nom;
}
} |
code src/map/Ecole.hbm.xml
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="essai1.ecole" table="ecole">
<id name="id_ecole" type="java.lang.Integer" column="id_ecole">
<generator class="increment"/>
</id>
<property name="nom_ecole" type="java.lang.String">
<column name="nom_ecole"/>
</property>
</class>
</hibernate-mapping> |
code src/map/hibernate.cfg.xml
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| <?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">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/essaihibernate</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">125487</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="current_session_context_class">thread</property>
<property name="connection.pool_size">1</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<mapping resource="map/Ecole.hbm.xml"/>
</session-factory>
</hibernate-configuration> |
code src/util/HibernateUtil
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| package util;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
public static final SessionFactory sessionFactory = new Configuration()
.configure("map/hibernate.cfg.xml").buildSessionFactory();
static {
try {
getSessionFactory();
} catch (Throwable ex) {
System.err.println("InitialSessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
} |
code src/essai1/GestionEcole.java
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
| package essai1;
import org.hibernate.classic.Session;
import util.HibernateUtil;
public class GestionEcole {
public void ajouterEcole(String nom_ecole) {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
ecole e = new ecole();
session.save(e);
session.getTransaction().commit();
System.out.println("Ajout effectué avec succès");
}
public static void main(String[] args) {
GestionEcole gp = new GestionEcole();
gp.ajouterEcole("Ecole1");
gp.ajouterEcole("Ecole2");
}
} |
Quelqu'un saurait-il m'expliquer d'où vient le problème ?
Merci d'avance pour votre aide.