Bonjour,
je développe mon application en Hibernate/Spring/Jsf , je dois développer un module de recherche multicritère, pour cela je veux utiliser Hibernate search , en suivant le guide d'utilisation "j'utilise la dernière version de hibernate-search.jar" , j'ai eu un problème au niveau de la session je sais pas comment il faut la créer , en utilisant sessionFactory j'ai eu un problème de conversion.

j'ai testé sur ma table mappé Utilisateur dans le code 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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153


// Generated 5 avr. 2012 23:43:32 by Hibernate Tools 3.4.0.CR1

import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.search.annotations.Analyze;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.IndexedEmbedded;
import org.hibernate.search.annotations.Store;



/**
 * Utilisateur generated by hbm2java
 */
@Entity
@Indexed
@Table(name = "UTILISATEUR", schema = "ADM")
public class Utilisateur implements java.io.Serializable {
	
	private String codeutilisateur;
	private Service service;
	
	@Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO)
	private String nomutilisateur;
	
	
	private String telephone;
	private String mail;
	private Set<Service> services = new HashSet<Service>(0);
	
	@IndexedEmbedded
	private Set<Profil> profils = new HashSet<Profil>(0);

	public Utilisateur() {
	}

	public Utilisateur(String codeutilisateur, Service service,
			String nomutilisateur, String telephone, String mail) {
		this.codeutilisateur = codeutilisateur;
		this.service = service;
		this.nomutilisateur = nomutilisateur;
		this.telephone = telephone;
		this.mail = mail;
	}

	public Utilisateur(String codeutilisateur, Service service,
			String nomutilisateur, String telephone, String mail,
			Set<Service> services, Set<Profil> profils) {
		this.codeutilisateur = codeutilisateur;
		this.service = service;
		this.nomutilisateur = nomutilisateur;
		this.telephone = telephone;
		this.mail = mail;
		this.services = services;
		this.profils = profils;
	}

	@Id
	
	@Column(name = "CODEUTILISATEUR", unique = true, nullable = false, length = 50)
	public String getCodeutilisateur() {
		return this.codeutilisateur;
	}

	public void setCodeutilisateur(String codeutilisateur) {
		this.codeutilisateur = codeutilisateur;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "CODESERVICE", nullable = false)
	public Service getService() {
		return this.service;
	}

	public void setService(Service service) {
		this.service = service;
	}

	@Column(name = "NOMUTILISATEUR", nullable = false, length = 50)
	public String getNomutilisateur() {
		return this.nomutilisateur;
	}

	public void setNomutilisateur(String nomutilisateur) {
		this.nomutilisateur = nomutilisateur;
	}

	@Column(name = "TELEPHONE", nullable = false, length = 50)
	public String getTelephone() {
		return this.telephone;
	}

	public void setTelephone(String telephone) {
		this.telephone = telephone;
	}

	@Column(name = "MAIL", nullable = false, length = 50)
	public String getMail() {
		return this.mail;
	}

	public void setMail(String mail) {
		this.mail = mail;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "utilisateur")
	public Set<Service> getServices() {
		return this.services;
	}

	public void setServices(Set<Service> services) {
		this.services = services;
	}
	
	
	
	@ManyToMany(fetch = FetchType.EAGER)
	@JoinTable(name = "UTILISATEURPROFIL", schema = "ADM", joinColumns = { @JoinColumn(name = "CODEUTILISATEUR", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "IDPROFIL", nullable = false, updatable = false) })
	public Set<Profil> getProfils() {
		return this.profils;
	}

	public void setProfils(Set<Profil> profils) {
		this.profils = profils;
	}
	
	public void addToProfil(Profil profil) {
	    this.getProfils().add(profil);
	    profil.getUtilisateurs().add(this);
	}

	public void removeFromProfil(Profil profil) {
	    this.getProfils().remove(profil);
	    profil.getUtilisateurs().remove(this);
	}

}
j'ai fait l'indexation sur une seul champ juste pour tester , et dans ma classe UtilisateurService j'ai défini la méthode rechercheUtilisateur

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
 
package ma.tgr.gestionExigences.parametrage.service;
 
import java.util.List;
 
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.search.FullTextSession;
import org.hibernate.search.Search;
import org.hibernate.search.query.dsl.QueryBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import ma.tgr.gestionExigences.parametrage.model.Utilisateur;
 
@Service("utilisateurService")
@Transactional
public class UtilisateurServiceImpl implements UtilisateurService {
 
	@Autowired
	private SessionFactory sessionFactory;
 
	private Session session;
 
	@Override
	@SuppressWarnings("unchecked")
	public List<Utilisateur> findAllUtilisateur() {
 
		return sessionFactory.getCurrentSession()
				.createQuery("from Utilisateur").list();
	}
 
	@SuppressWarnings("unchecked")
	@Override
	public Utilisateur findByIdUtilisateur(int id) {
 
		return (Utilisateur) sessionFactory.getCurrentSession().get(
				Utilisateur.class, id);
	}
 
	@Override
	public void saveUtilisateur(Utilisateur utilisateur) {
		sessionFactory.getCurrentSession().save(utilisateur);
 
	}
 
	@Override
	public void updateUtilisateur(Utilisateur utilisateur) {
		sessionFactory.getCurrentSession().update(utilisateur);
 
	}
 
	@Override
	public void supprimerUtilisateur(Utilisateur utilisateur) {
		sessionFactory.getCurrentSession().delete(utilisateur);
 
	}
 
	@SuppressWarnings("unchecked")
	@Override
	public List<Utilisateur> rechercheUtilisateur() {
 
		session = sessionFactory.openSession();
 
		FullTextSession fullTextSession = Search.getFullTextSession(session);
		Transaction tx = fullTextSession.beginTransaction();
 
		QueryBuilder qb = fullTextSession.getSearchFactory()
				.buildQueryBuilder().forEntity(Utilisateur.class).get();
		org.apache.lucene.search.Query query = qb.keyword()
				.onFields("codeutilisateur").matching("test").createQuery();
		// wrap Lucene query in a org.hibernate.Query
		org.hibernate.Query hibQuery = fullTextSession.createFullTextQuery(
				query, Utilisateur.class);
		// execute search
		List<Utilisateur> result = hibQuery.list();
 
		tx.commit();
		session.close();
		return result;
 
	}
 
}
le souci c'est que lorsque je teste la methode rechercheUtilisateur(), j'ai l'erreur suivante :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
 
javax.servlet.ServletException: java.lang.ClassCastException: org.hibernate.impl.SessionImpl cannot be cast to org.hibernate.event.spi.EventSource
le problème se trouve au niveau de la création de la session mais je sais pas comment y remédier :s