Bonjour,

Je tente d'utiliser hibernate.
J'ai sous mon répertoire web-inf, un fichier hibernate.cfg.xml
Voici son contenu:
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
 
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
 
<hibernate-configuration>
<session-factory>
      <property name="hibernate.connection.driver_class">
 
oracle.jdbc.driver.OracleDriver</property>
      <property name="hibernate.connection.url">
 
jdbc:oracle:thin:@myserver:1521:mydb</property>
      <property name="hibernate.connection.username">user</property>
      <property name="hibernate.connection.password">pwd</property>
      <property name="hibernate.connection.pool_size">10</property>
      <property name="show_sql">true</property>
      <property name="dialect">org.hibernate.dialect.OracleDialect</property>
      <property name="hibernate.hbm2ddl.auto">update</property>
      <!-- Mapping files -->
      <mapping resource="branch.hbm.xml"/>
</session-factory>
</hibernate-configuration>
J'ai mon fichier branch.hbm.xml placé au même endroit :
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
 
<?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>
  <class name="testhibern.bean.Branch" table="schema.branch">
   <id name="id" type="long" column="ind_id">
   <generator class="assigned"/>
  </id>
  <property name="code">
     <column name="br_code" />
  </property>
  <property name="director">
     <column name="br_dir" />
  </property>
  <property name="name">
     <column name="br_name" />
  </property>
  <property name="type">
    <column name="br_type"/>
  </property>
 </class>
</hibernate-mapping>
le tout est appelé de ma servlet qui est placée sous le répertoire src + nom du package
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
 
package testhibern;
 
import java.io.IOException;
 
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
 
import testhibern.bean.Branch;
 
 
/**
 * @author 
 *
 *
 * Hibernate insert data into Branch  table
 */
public class FirstExample extends HttpServlet{
 
 
	/**
         * 
         */
	private static final long serialVersionUID = -7841874428262567796L;
 
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		 Session session = null;
 
		    try{
		      // This step will read hibernate.cfg.xml and prepare hibernate for use
		      SessionFactory sessionFactory = new 
 
		Configuration().configure().buildSessionFactory();
		       session =sessionFactory.openSession();
		        //Create new instance of Contact and set values in it by reading them from form object
		         System.out.println("Inserting Record");
		        Branch branch = new Branch();
		        branch.setCode("1337");
		        branch.setDirector("USER");
		        branch.setName("Agence Fantôme test");
		        branch.setType(1);
		        session.save(branch);
		        System.out.println("Done");
		    }catch(Exception e){
		      System.out.println(e.getMessage());
		    }finally{
		      // Actual contact insertion will happen at this step
		      session.flush();
		      session.close();
		      }
		  }
}
Et j'ai ce joli message d'erreur :
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
 
2010-11-30 14:45:00,981 ERROR [[FirstExample]] "Servlet.service()" pour la servlet FirstExample a généré une exception
java.lang.NullPointerException
	at testhibern.FirstExample.doGet(FirstExample.java:56)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:693)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.geronimo.tomcat.valve.DefaultSubjectValve.invoke(DefaultSubjectValve.java:56)
	at org.apache.geronimo.tomcat.GeronimoStandardContext$SystemMethodValve.invoke(GeronimoStandardContext.java:406)
	at org.apache.geronimo.tomcat.valve.GeronimoBeforeAfterValve.invoke(GeronimoBeforeAfterValve.java:47)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:567)
	at org.apache.geronimo.tomcat.valve.ThreadCleanerValve.invoke(ThreadCleanerValve.java:40)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
	at java.lang.Thread.run(Unknown Source)
Apparemment il ne trouve donc pas mon fichier de configuration hibernate.cfg.xml

Pourriez-vous m'aider ?