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 :

Hibernate: problème avec currentSession()


Sujet :

Hibernate Java

  1. #1
    Membre régulier Avatar de KneXtasY
    Profil pro
    Inscrit en
    Mars 2004
    Messages
    121
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2004
    Messages : 121
    Points : 109
    Points
    109
    Par défaut Hibernate: problème avec currentSession()
    Bonjour,

    lors d'un appel à un webservice, j'obtiens dans l'enveloppe réponse, l'erreur suivante :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    <faultcode>soapenv:Server.userException</faultcode> 
      <faultstring>java.lang.reflect.InvocationTargetException</faultstring>
    Le code executé lors de l'appel est le suivant :

    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
    try { 
        	      System.out.println("Initialisation ...");
        	      Session session = HibernateUtil.currentSession(); 
        	      System.out.println("Session ...");
        	      Transaction tx = session.beginTransaction(); 
     
        	      System.out.println("Création du client");
        	      Client personne = new Client(); 
        	      personne.setNom("nom"); 
        	      personne.setPrenom("prenom"); 
        	      session.save(personne); 
        	      System.out.println("save du client");
     
        	      tx.commit(); 
        	      HibernateUtil.closeSession();
        	      System.out.println("Fin de la session !");
        	    } catch (HibernateException e) { 
        	    	System.out.println("[Erreur] HibernateException");
        	    	e.printStackTrace();
        	    }
    La console Eclipse affiche juste : Initialisation ...
    Donc l'erreur doit venir de Session session = HibernateUtil.currentSession();

    Classe 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
    31
    32
    33
    34
    35
    36
    import net.sf.hibernate.*; 
    import net.sf.hibernate.cfg.*; 
     
    public class HibernateUtil { 
     
      private static final SessionFactory sessionFactory; 
     
      static { 
        try { 
          sessionFactory = new Configuration().configure() 
                                  .buildSessionFactory(); 
        } catch (HibernateException ex) { 
          throw new RuntimeException("Exception building SessionFactory: " 
                + ex.getMessage(), ex); 
        } 
      } 
     
      public static final ThreadLocal session = new ThreadLocal(); 
     
      public static Session currentSession() throws HibernateException { 
        Session s = (Session) session.get(); 
        // Open a new Session, if this Thread has none yet 
        if (s == null) { 
          s = sessionFactory.openSession(); 
          session.set(s); 
        } 
        return s; 
      } 
     
      public static void closeSession() throws HibernateException { 
        Session s = (Session) session.get(); 
        session.set(null); 
        if (s != null) 
          s.close(); 
      } 
    }
    Je précise qu'aucune action n'est effectuée sur ma DB.

    Quelqu'un peut-il m'aider ?

    Merci d'avance !

  2. #2
    Membre actif Avatar de coco62
    Profil pro
    Inscrit en
    Mars 2004
    Messages
    237
    Détails du profil
    Informations personnelles :
    Âge : 53
    Localisation : France

    Informations forums :
    Inscription : Mars 2004
    Messages : 237
    Points : 278
    Points
    278
    Par défaut
    Cela doit venir de ta config hibernate , elle est chargé a l'initialisation.

    Affiche la stack en cas d'erreur dans HibernateUtil

  3. #3
    Membre régulier Avatar de KneXtasY
    Profil pro
    Inscrit en
    Mars 2004
    Messages
    121
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2004
    Messages : 121
    Points : 109
    Points
    109
    Par défaut
    PrintStackTrace() n'a rien donnée !

    Est ce normal que j'obtienne ceci ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14 mai 2007 18:05:53 net.sf.hibernate.cfg.Environment <clinit>
    INFO: Hibernate 2.1.6
    14 mai 2007 18:05:53 net.sf.hibernate.cfg.Environment <clinit>
    INFO: hibernate.properties not found
    14 mai 2007 18:05:53 net.sf.hibernate.cfg.Environment <clinit>
    INFO: using CGLIB reflection optimizer
    14 mai 2007 18:05:53 net.sf.hibernate.cfg.Configuration configure
    INFO: configuring from resource: /hibernate.cfg.xml
    14 mai 2007 18:05:53 net.sf.hibernate.cfg.Configuration getConfigurationInputStream
    INFO: Configuration resource: /hibernate.cfg.xml
    14 mai 2007 18:05:53 net.sf.hibernate.cfg.Configuration addResource
    INFO: Mapping resource: Client.hbm
    Initialisation ...

  4. #4
    Membre régulier Avatar de KneXtasY
    Profil pro
    Inscrit en
    Mars 2004
    Messages
    121
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2004
    Messages : 121
    Points : 109
    Points
    109
    Par défaut
    Il y avait bien une erreur dans le fichier de mapping ...

    Merci !

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. hibernate : problème avec update
    Par sel3aa dans le forum Hibernate
    Réponses: 3
    Dernier message: 17/02/2009, 10h02
  2. Réponses: 3
    Dernier message: 14/08/2007, 13h04
  3. [HIBERNATE] Problème avec ant
    Par DarkWark dans le forum Hibernate
    Réponses: 1
    Dernier message: 04/06/2006, 19h55
  4. [Hibernate] Problème avec xDoclet
    Par srvremi dans le forum Hibernate
    Réponses: 1
    Dernier message: 24/05/2006, 12h34
  5. [Hibernate] Problème avec Hibernate et Eclipse 3
    Par theseuby dans le forum Eclipse Java
    Réponses: 1
    Dernier message: 30/03/2006, 21h31

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