bonjour,
voila j'ai un souci!
voila le doGet de ma servlet:
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 public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { // on récupère les paramètres String nom = request.getParameter("txtNom"); //on ouvre la session et on recupere les profils dont le nom est "nom" Session ss = HibernateUtil.currentSession(); Transaction tx = ss.beginTransaction(); Query q = ss.createQuery("from hibernate.Profil p where p.nom='"+nom+"'"); List l=q.list(); ArrayList<Profil> Profil=new ArrayList<Profil>(); while(l.iterator().hasNext()) { candidat.add((Profil)l.iterator().next()); } tx.commit(); HibernateUtil.closeSession(); //on passe le profil en parametre request.setAttribute("profil", profil); //redirection getServletContext().getRequestDispatcher(urlReponse).forward(request,response); return; }
ma classe HibernateUtil :
mais quand je vais sur ma page que je rentre dans la servlet longlet debug d'eclipse souvre et m'indique que la ligne du lancement de l'exception "RuntimeException" de la classe HibernatUtilCode:
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 package util; import org.hibernate.*; import org.hibernate.cfg.*; public class HibernateUtil { private static final SessionFactory sessionFactory; static { try { // Crée la SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); } catch (HibernateException ex) { throw new RuntimeException("Problème de configuration : "+ ex.getMessage(), ex); } } public static final ThreadLocal session = new ThreadLocal(); public static Session currentSession()throws HibernateException { Session s = (Session) session.get(); // Ouvre une nouvelle Session, si ce Thread n'en a aucune 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(); } }
voila vous avez une solution sachant que les requetes fonctionnent