Bonjour,
j'essaye de réaliser un helloworld avec eclipse, hibernate 3.2, et mysql.
J'ai une erreur que j'arrive pas à résoudre. la voici:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
Exception in thread "main" java.lang.ExceptionInInitializerError
	at com.hello.HibernateUtil.<clinit>(HibernateUtil.java:17)
	at com.hello.HelloWorld.main(HelloWorld.java:13)
Caused by: org.hibernate.MappingNotFoundException: resource: com.hello/Messages.hbm.xml not found
	at org.hibernate.cfg.Configuration.addResource(Configuration.java:517)
	at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1511)
	at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1479)
	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1458)
	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1432)
	at org.hibernate.cfg.Configuration.configure(Configuration.java:1352)
	at org.hibernate.cfg.Configuration.configure(Configuration.java:1338)
	at com.hello.HibernateUtil.<clinit>(HibernateUtil.java:15)
	... 1 more
J'ai cette erreur alors que mon fichier Messages.hbm.xml est dans le dossier sources

code de HibernateUtil:
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
package com.hello;
 
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();
  }
}
code de HelloWorld:
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package com.hello;
 
import org.hibernate.*;
import java.util.*;
 
public class HelloWorld {
 
    public static void main(String[] args) {
 
        // ############################################################################
 
        // First unit of work
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction tx = session.beginTransaction();
 
        Message message = new Message("Hello World");
        session.save(message);
 
        tx.commit();
        session.close();
 
        // ############################################################################
 
        // Second unit of work
        Session secondSession = HibernateUtil.getSessionFactory().openSession();
        Transaction secondTransaction = secondSession.beginTransaction();
 
        List messages =
            secondSession.createQuery("from Message m order by m.text asc").list();
 
        System.out.println( messages.size() + " message(s) found:" );
 
        for ( Iterator iter = messages.iterator(); iter.hasNext(); ) {
            Message loadedMsg = (Message) iter.next();
            System.out.println( loadedMsg.getText() );
        }
 
        secondTransaction.commit();
        secondSession.close();
 
        // ############################################################################
 
        // Third unit of work
        Session thirdSession = HibernateUtil.getSessionFactory().openSession();
        Transaction thirdTransaction = thirdSession.beginTransaction();
 
        // message.getId() holds the identifier value of the first message
        Message loadedMessage = (Message) thirdSession.get( Message.class, message.getId());
        loadedMessage.setText( "Greetings Earthling" );
        loadedMessage.setNextMessage(
            new Message( "Take me to your leader (please)" )
        );
 
        thirdTransaction.commit();
        thirdSession.close();
 
        // ############################################################################
 
        // Final unit of work (just repeat the query)
        // TODO: You can move this query into the thirdSession before the commit, makes more sense!
        Session fourthSession = HibernateUtil.getSessionFactory().openSession();
        Transaction fourthTransaction = fourthSession.beginTransaction();
 
        messages =
            fourthSession.createQuery("from Message m order by m.text asc").list();
 
        System.out.println( messages.size() + " message(s) found:" );
 
        for ( Iterator iter = messages.iterator(); iter.hasNext(); ) {
            Message loadedMsg = (Message) iter.next();
            System.out.println( loadedMsg.getText() );
        }
 
        fourthTransaction.commit();
        fourthSession.close();
 
 
        // Shutting down the application
        HibernateUtil.shutdown();
    }
}
Est ce que quelqu'un a une idée.
Merci d'avance.