Bonjour à tous .
Quand je find un element et que je tente de faire un update il me renvoie cet erreur :Illegal attempt to associate a collection with two open sessions
Voici ma configurartion:
genericDaogenericdaoImpl
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 public interface GenericDao<T, PK extends Serializable> { PK save(T newInstance); T findById(PK id); List<T> findAll(); void update(T transientObject); void remove(T persistentObject); void saveOrUpdate(T object); }et ma classe service :
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 public class GenericDaoImpl<T, PK extends Serializable> implements GenericDao<T, PK> { @Autowired private SessionFactory sessionFactory; private Class<T> type; public GenericDaoImpl() { super(); } public void saveOrUpdate(T o) { getSession().saveOrUpdate(o); } public GenericDaoImpl(Class<T> type) { this.type = type; } public PK save(T o) { return (PK) getSession().save(o); } public T findById(PK id) { return (T) getSession().get(type, id); } public List<T> findAll() { Criteria crit = getSession().createCriteria(type); crit.add(Restrictions.eq("enabled", new Boolean(true))); return crit.list(); } public void update(T o) { getSession().update(o); } public void merge(T o) { getSession().merge(o); } public void remove(T o) { getSession().delete(o); } public Session getSession() { boolean allowCreate = true; return SessionFactoryUtils.getSession(sessionFactory, allowCreate); } public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } }
Quand je fais cette commande :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 @Transactional @Service("SfdService") public class SfdServiceImpl extends GenericDaoImpl<Sfd, Integer>implements SfdService,Serializable{ public SfdServiceImpl(Class<Sfd> type) { super(type); } public SfdServiceImpl() { super(); } }
Sfd sfd=sfdService.findById(1);
sfd.setNom("changeName");
sfdService.save(sfd);
J'ai l'erreur "org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions"
Je suspecte ma "getsession" parceque je crois qu'il cree une nouvelle session à chaque appel.
Pouvez vous m'aidez SVP!
Partager