Bonjour,


J'essaie d'utiliser Hibernate pour accéder à ma base Oracle mais j'ai cette 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
 
ATTENTION: Could not bind factory to JNDI
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
	at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
	at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
	at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
	at javax.naming.InitialContext.getNameParser(Unknown Source)
	at org.hibernate.util.NamingHelper.bind(NamingHelper.java:52)
	at org.hibernate.impl.SessionFactoryObjectFactory.addInstance(SessionFactoryObjectFactory.java:90)
	at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:306)
	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
	at utility.HibernateUtility.getSessionFactory(HibernateUtility.java:30)
	at utility.HibernateUtility.openSession(HibernateUtility.java:45)
	at utility.HibernateUtility.main(HibernateUtility.java:82)
Ma classe HibernateUtility est la 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
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
82
83
84
85
86
87
88
89
90
91
 
package utility;
 
import java.util.logging.Logger;
 
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
 
import com.axione.ihm.planning.DAO.test.TestDiffusionPlanningInstallateur;
 
 
 
public class HibernateUtility {
 
	private static transient Logger logger = Logger.getLogger(HibernateUtility.class.getName());
 
	public static SessionFactory SF;
	private static final ThreadLocal<Session> SESSION_TL = new ThreadLocal<Session>();
    public static final ThreadLocal session = new ThreadLocal();
    private static final String CONFIG_FILE = "hibernate.cfg.xml";
 
 
 
    private static SessionFactory getSessionFactory(){
		if (SF == null) {
			logger.info("SF :"+SF);
	        try {
				//SF = new Configuration().configure(CONFIG_FILE).buildSessionFactory();
	        	SF = new Configuration().configure().buildSessionFactory();
			} catch (HibernateException e) {
				throw new RuntimeException("Problème de configuration : "
						+ e.getMessage(), e);
			}
			logger.info("Ouverture de la Session");}
	    return SF;
		}
    /*
     * cree la session hibernate pour le thread courant
     * 
     * */
    public static Session openSession() throws HibernateException {
    	Session vSession = (Session) SESSION_TL.get();
        if (vSession == null) {
          vSession = getSessionFactory().openSession();
          SESSION_TL.set(vSession);
        }
        logger.info("Création session hibernate pour le thread courant");
        return vSession;
      }
 
    /*
	 * recupere la session courante
	 * 
	 * */
    public static Session currentSession() throws HibernateException {
		 Session vSession = (Session) SESSION_TL.get();
		 if (vSession == null) {
			 vSession = SF.openSession();
			 SESSION_TL.set(vSession);
			 logger.info("Récupération de la Session courante");
		}
		return vSession;
	  }
 
    /*
	 * fermer la session courante
	 * 
	 * */
    public static void closeSession() throws HibernateException {
		Session vSession = (Session) SESSION_TL.get();
		SESSION_TL.set(null);
	      if (vSession != null) {
	    	  logger.info("Femeture de la Session courante");
	    	  vSession.close();
	      }
	}
 
    public static void main(String[] args) {
 
    	//creer une sessionFacotry
    	HibernateUtility.openSession();
 
    	//fermer la session
		HibernateUtility.closeSession();
 
	}
 
 
}
Et mon fichier hibernate.cfg.xml comme suit :

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
 
<?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="AXIONEUSER_MIGRATION">
 
		<!-- utilisation parametres de connexion en dur pour les tests en contexte local -->
        <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="hibernate.connection.url">jdbc:oracle:thin:@10.210.1.2:1521:****</property>
		<property name="hibernate.connection.username">AXIONEUSER_MIGRATI*****</property>
		<property name="hibernate.connection.password">*****</property>
        <property name="hibernate.default_schema">***</property>
 
		<!-- Enable Hibernate's automatic session context management -->
		<!--
        <property name="current_session_context_class">thread</property>
			-->
 
		<!-- dialect for Oracle -->
        <property name="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</property>
 
		<!-- sans cache -->
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
 
		<!-- Table -->
		<!--
        <mapping resource="com/axione/ihm/planning/AboAbonnes.hbm.xml"/>
		<mapping resource="com/axione/ihm/planning/AboDsp.hbm.xml"/>
		<mapping resource="com/axione/ihm/planning/AboFai.hbm.xml"/>
		<mapping resource="com/axione/ihm/planning/AboInstallateurs.hbm.xml"/>
 
		<mapping resource="com/axione/ihm/planning/CreCalendrier.hbm.xml"/>
		<mapping resource="com/axione/ihm/planning/CreCreneaux.hbm.xml"/>
		<mapping resource="com/axione/ihm/planning/CreCreneauxDates.hbm.xml"/>
		<mapping resource="com/axione/ihm/planning/CreDates.hbm.xml"/>
		<mapping resource="com/axione/ihm/planning/CreDsp.hbm.xml"/>
		<mapping resource="com/axione/ihm/planning/CreExceptions.hbm.xml"/>
		<mapping resource="com/axione/ihm/planning/CreInstallateurs.hbm.xml"/>
		<mapping resource="com/axione/ihm/planning/CreJoursFeries.hbm.xml"/>
		<mapping resource="com/axione/ihm/planning/CreParametres.hbm.xml"/>
		<mapping resource="com/axione/ihm/planning/CreRendezVous.hbm.xml"/>
		<mapping resource="com/axione/ihm/planning/CreTypeIntervention.hbm.xml"/>
 
		<mapping resource="com/axione/ihm/planning/StoDsp.hbm.xml"/>
		<mapping resource="com/axione/ihm/planning/StoEquipement.hbm.xml"/>
		<mapping resource="com/axione/ihm/planning/StoEtatequipement.hbm.xml"/>
		<mapping resource="com/axione/ihm/planning/StoPrestataires.hbm.xml"/>
		<mapping resource="com/axione/ihm/planning/StoTypeEquipement.hbm.xml"/>
		-->
		<!-- Queries -->
		<!--
		<mapping resource="com/axione/ihm/planning/queries/Queries.hbm.xml"/>
		-->
 
    </session-factory>
</hibernate-configuration>
Y-t-il une personne en mesure de m'aider svp

Cordialement Lazarel