Conversation injection is null
derkd Aug 16, 2011 6:20 AMHi all,
I have a ViewScoped bean where I want to inject de conversation in. In the logging I see that the conversation id is null. I use JBoss 6 but I also tested this with jboss 7. Does anybody have any ideas?
@Stateful @ConversationScoped @Named public class CategoryManager { /** * */ private static final long serialVersionUID = 9179727796959552384L; private static final Logger log = Logger.getLogger(CategoryManager.class); @PersistenceContext(type= PersistenceContextType.EXTENDED) private EntityManager entityManager; private Long categoryId; @Inject private Conversation conversation; @Produces @Named public List<Category> getRootCategories() { log.debug("entered getRootCategories"); if(!conversation.isTransient()) { conversation.begin(); log.debug("not transient - conversation id: " + conversation.getId()); System.out.println("not transient - conversation id: " + conversation.getId()); } log.debug("conversation id: " + conversation.getId()); System.out.println("conversation id: " + conversation.getId()); if(getCategoryId() == null) { log.debug("categoryId == null"); CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<Category> cquery = builder.createQuery(Category.class); Root<Category> category = cquery.from(Category.class); cquery.select(category).where(builder.isNull(category.get("previousCategory"))); List<Category> rootCategories = entityManager.createQuery(cquery).getResultList(); return rootCategories; }else{ log.debug("categoryId != null so return category with selected Id and underlying categoryList"); CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<Category> cquery = builder.createQuery(Category.class); Root<Category> category = cquery.from(Category.class); cquery.select(category).where(builder.equal(category.get(Category_.id), categoryId)); List<Category> rootCategories = entityManager.createQuery(cquery).getResultList(); return rootCategories; } } @Produces @Named("category") public Category getCategory() { log.debug("entered getCategory"); if(categoryId != null) { log.info("categoryId: " + categoryId); Category cat = entityManager.find(Category.class, categoryId); log.info("size of categories of the selected category: " + cat.getCategories().size()); return cat; }else{ log.info("categoryId == null"); log.info("create new category"); return new Category(); } } @Produces @Named @nl.ami.marketplace.market.Category public Long getCategoryId() { log.debug("getCategoryId: " + categoryId); return categoryId; } public void setCategoryId(Long categoryId) { this.categoryId = categoryId; } }