Hibernate: problème avec currentSession()
Bonjour,
lors d'un appel à un webservice, j'obtiens dans l'enveloppe réponse, l'erreur suivante :
Code:
1 2
| <faultcode>soapenv:Server.userException</faultcode>
<faultstring>java.lang.reflect.InvocationTargetException</faultstring> |
Le code executé lors de l'appel est le suivant :
Code:
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 ... :roll:
Donc l'erreur doit venir de Session session = HibernateUtil.currentSession();
Classe HibernateUtil :
Code:
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 ? :cry:
Merci d'avance !