Bonjour,
Je suis bloqué sur une exeption depuis hier , j'ai essayé de magouillé mais rien ne fonctionne.
Voici mon fichier hibernate.cfg.xml
Code xml : 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"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory name=""> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/testhib</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password">root</property> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <mapping resource="appliTest/Test.hbm.xml" /> </session-factory> </hibernate-configuration>
MA class test
Mon ficher test.hbm.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 package appliTest ; public class Test { private Long id ; // type référence préférable car pointeur null private String nom ; private int nbRayons ; public Test() { this.id = null ; this.nom = null ; this.nbRayons = 0 ; } public Test(String nom) { this.id = null ; // affecté par Hibernate, voir Responsable.hbm.xml this.nom = nom ; this.nbRayons = 0 ; } void setId (Long id) { this.id = id ;} public Long getId () {return id ;} public void setNom (String nom) { this.nom = nom ;} public String getNom () { return nom ;} public void setNbRayons (int nbRayons) { this.nbRayons = nbRayons ;} public int getNbRayons () { return nbRayons ;} public void addNbRayons (int n) { this.nbRayons += n ;} }
Code xml : 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 <?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 package="appliTest" > <class name="Test" table="TEST"> <id name="id" type="long" column="id"> <generator class="native"> </generator> </id> <property name="nom" column="nom" length="20"/> </class> </hibernate-mapping>
Ma Classe HibernateUtil
Ma class d exec
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 package appliTest; import org.hibernate.*; import org.hibernate.cfg.*; /** * Startup Hibernate and provide access to the singleton SessionFactory */ public class HibernateUtil { private static SessionFactory sessionFactory; static { try { sessionFactory = new Configuration().configure().buildSessionFactory(); } catch (Throwable ex) { throw new ExceptionInInitializerError(ex); } } public static SessionFactory getSessionFactory() { // Alternatively, we could look up in JNDI here return sessionFactory; } public static void shutdown() { // Close caches and connection pools getSessionFactory().close(); } }
lors de l exec ca me retourne ==>
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 import net.sf.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; import appliTest.HibernateUtil; import appliTest.Test; public class Exec { public static void main(String[] args) throws HibernateException { System.out.println("1"); Session session = HibernateUtil.getSessionFactory().openSession(); System.out.println("2"); Transaction tx = session.beginTransaction(); System.out.println("3"); Test contact = new Test(); contact.setNom("Dupont"); System.out.println("4"); session.save(contact); System.out.println("5"); System.out.println("+++++++++++++++++++++++"+ contact.getNom()); contact.setNom("Lambert"); session.save(contact); tx.commit(); session.close(); } }
Exception in thread "main" java.lang.ExceptionInInitializerError
at appliTest.HibernateUtil.<clinit>(HibernateUtil.java:17)
at Exec.main(Exec.java:18)
Caused by: java.lang.NoSuchMethodError: net.sf.cglib.proxy.Enhancer.setInterceptDuringConstruction(Z)V
at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:120)
at org.hibernate.proxy.pojo.cglib.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:43)
at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:162)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:135)
at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:55)
at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:56)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:269)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:425)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:109)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1218)
at appliTest.HibernateUtil.<clinit>(HibernateUtil.java:15)
... 1 more
Merci de m'aider
![]()
Partager