IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Hibernate Java Discussion :

[3.2.3]Erreur Could not bind factory to JNDI


Sujet :

Hibernate Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre émérite
    Avatar de lazarel
    Homme Profil pro
    Consultant informatique
    Inscrit en
    Mai 2007
    Messages
    893
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Consultant informatique
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Mai 2007
    Messages : 893
    Par défaut [3.2.3]Erreur Could not bind factory to JNDI
    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

  2. #2
    Membre confirmé
    Inscrit en
    Avril 2008
    Messages
    184
    Détails du profil
    Informations personnelles :
    Âge : 49

    Informations forums :
    Inscription : Avril 2008
    Messages : 184
    Par défaut
    Bonjour,

    J'ai exactement le meme pb...

    Youkoun

  3. #3
    Membre émérite
    Avatar de lazarel
    Homme Profil pro
    Consultant informatique
    Inscrit en
    Mai 2007
    Messages
    893
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Consultant informatique
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Mai 2007
    Messages : 893
    Par défaut
    ^^ cool je ne suis pas un isolé

  4. #4
    Membre chevronné Avatar de djsnipe
    Inscrit en
    Mai 2008
    Messages
    440
    Détails du profil
    Informations forums :
    Inscription : Mai 2008
    Messages : 440
    Par défaut
    Citation Envoyé par lazarel Voir le message
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <session-factory name="AXIONEUSER_MIGRATION">
    Le "name" demande à Hibernate d'enregistrer la SessionFactory dans l'environnement JNDI du serveur d'application, et ainsi la récupérer ensuite depuis JNDI au lieu de le faire depuis un Singleton par exemple. Pour cela il faut les informations de connexion à l'arbre JNDI comme indiqué dans la stack.
    Si l'accès JNDI ne vous sert pas, supprimer l'attribut "name" du fichier de config. Hibernate.

  5. #5
    Membre émérite
    Avatar de lazarel
    Homme Profil pro
    Consultant informatique
    Inscrit en
    Mai 2007
    Messages
    893
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Consultant informatique
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Mai 2007
    Messages : 893
    Par défaut
    Ok,


    Merci djsnipe ça marche nikel


    Cordialement,

  6. #6
    Membre confirmé
    Inscrit en
    Avril 2008
    Messages
    184
    Détails du profil
    Informations personnelles :
    Âge : 49

    Informations forums :
    Inscription : Avril 2008
    Messages : 184
    Par défaut
    Merci de ta reponse.

  7. #7
    Membre éclairé Avatar de liquideshark
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Septembre 2006
    Messages
    347
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Service public

    Informations forums :
    Inscription : Septembre 2006
    Messages : 347
    Par défaut
    salut

    commment ? suprimer le name povez vous poster un exemple

    merci

  8. #8
    Membre confirmé
    Inscrit en
    Avril 2008
    Messages
    184
    Détails du profil
    Informations personnelles :
    Âge : 49

    Informations forums :
    Inscription : Avril 2008
    Messages : 184
    Par défaut
    Salut,

    Il suffit d'enlever l'attribut "name" de l'element "session-factory".
    (Regarde les exemples plus haut)

Discussions similaires

  1. Réponses: 8
    Dernier message: 10/12/2014, 15h26
  2. Réponses: 3
    Dernier message: 02/09/2013, 08h51
  3. Réponses: 0
    Dernier message: 24/03/2012, 02h19
  4. Réponses: 6
    Dernier message: 20/04/2010, 11h09
  5. Réponses: 2
    Dernier message: 22/05/2007, 03h45

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo