In fact i was in a spring unit test and i was needed to put in the setup of my unit case in order to initialize the lazy collection :
sessionFactory = (SessionFactory) ctx.getBean("maSessionFactory");
Session session = SessionFactoryUtils.getSession(sessionFactory, true);
TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session));
If i close the connexion and reopen it between my save part ant the delete part it is ok :
entreprise.addContact(contact);
mgr.saveEntreprise(entreprise); // [daoEntreprise.save(entreprise);]
SessionHolder holder = (SessionHolder) TransactionSynchronizationManager.getResource(sessionFactory);
Session s = holder.getSession();
s.flush();
TransactionSynchronizationManager.unbindResource(sessionFactory);
SessionFactoryUtils.closeSessionIfNecessary(s, sessionFactory);
sessionFactory = (SessionFactory) ctx.getBean("maSessionFactory");
Session session = SessionFactoryUtils.getSession(sessionFactory, true);
TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session));
Entreprise e=mgr.getEntreprise(entreprise.getId().toString());
Contact c=mgr.getContact(contact.getId().toString());
e.getContacts().remove(c);
mgr.saveEntreprise(e);
Do you understand why ?
|