Bonjour,
Je travaille en ce moment sur un application java EE5, avec jsf, ejb3, jpa…
et je rencontre l’exeption suivante :
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.yaps.petstore.entity.catalog.Product.items, no session or session was closed

Voici mon code :
L’architecture est la suivante :
Jsf-->controller(managedBean)-->ejb stateless-->entityBean

Controller (CatalogController ):
public String doFindProducts() {

catalogBean=(CatalogLocal)new InitialContext().lookup("PetstoreEAR/CatalogBean/local");

category = catalogBean.findCategory(getParamId("categoryId"));
products =category.getProducts();
navigateTo = "products.displayed";
return navigateTo;


}
Ejb stateless:
public class CatalogBean implements CatalogRemote, CatalogLocal {

@PersistenceContext(unitName = "petstorePU")
private EntityManager em;
public Category findCategory(final Long categoryId) {

Category category;
category = em.find(Category.class, categoryId);
return category;
}

entityBean
j’ai un entity bean product
et un entityBean category qui a comme attribut une liste de product.

Apres avoir cherché sur plusieurs forum j’ai cru comprendre que l’erreur peut venir du fait qu’au moment de faire products =category.getProducts();
Dans le controller, alors l’entity category n’est plus rattaché au context de persistance.

Mais je ne sait toujours pas comment resoudre le probleme…

Merci d’avance a tous ceux qui prendront le temps de lire et de repondre.