Bonjour,
Excusez moi de vous déranger mais je suis un peu perdu. J'essaye de me connecter à une table d'une base de donnée et quand j'effectue l'action pour récupérer l'objet de type SessionFactory :J'obtiens l'erreur suivante :
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
38 public class HibernateCourseDao implements CourseDao { private SessionFactory sessionFactory; public HibernateCourseDao(){ try{ sessionFactory = new Configuration().configure().buildSessionFactory(); } catch(HibernateException e) { System.out.println(e.getMessage()); } } @Override public void store(Course course) { // TODO Auto-generated method stub Session session = sessionFactory.openSession(); Transaction tx = session.getTransaction(); try{ tx.begin(); session.saveOrUpdate(course); tx.commit(); } catch(RuntimeException e){ tx.rollback(); throw e; } finally{ session.close(); } } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 13:30:53,502 INFO Environment:543 - Hibernate 3.3.1.GA Exception in thread "main" java.lang.ExceptionInInitializerError at org.hibernate.cfg.Configuration.reset(Configuration.java:201) at org.hibernate.cfg.Configuration.<init>(Configuration.java:220) at org.hibernate.cfg.Configuration.<init>(Configuration.java:224) at com.apress.springrecipes.course.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:16) at com.apress.springrecipes.course.hibernate.HibernateCourseDao.store(HibernateCourseDao.java:36) at Main.main(Main.java:20) Caused by: java.lang.NullPointerException at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:167) at org.hibernate.cfg.Environment.<clinit>(Environment.java:558) ... 6 more
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 <?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.password">xxxx</property> <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/course</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <property name="hibernate.show_sql">true</property> <property name="hibernate.hbm2ddl.auto">update</property> <mapping resource="com/apress/springrecipes/course/Course.hbm.xml"/> </session-factory> </hibernate-configuration>
et le fichier Course.hbm.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
17
18
19
20
21
22
23
24 <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Generated 12 sept. 2011 09:48:17 by Hibernate Tools 3.4.0.CR1 --> <hibernate-mapping> <class name="com.apress.springrecipes.course.Course" table="COURSE"> <id name="id" type="java.lang.Long"> <column name="ID" /> <generator class="identity" /> </id> <property name="title" type="java.lang.String"> <column name="TITLE" /> </property> <property name="beginDate" type="java.util.Date"> <column name="BEGIN_DATE" /> </property> <property name="endDate" type="java.util.Date"> <column name="END_DATE" /> </property> <property name="fee" type="int"> <column name="FEE" /> </property> </class> </hibernate-mapping>
Aussi, je viens vous demander un peu d'aide.
Je vous remercie d'avance pour votre aide.
Cordialement
Vinou
PS: en pieces jointes deux "imprim ecran", la premiere montrant les librairies que j'ai mises (beaucoup sont importées notemment d'un répertoire où je stocke toutes les librairies) et la deuxieme concernant l'arborescence du répertoire source.
![]()
Partager