Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

EntityManager is null when I try to use it straight from filter servlet  RSS feed

Sami Nurmi
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

First JPA-EJB-JSF software for me so....

I am using facade pattern like Netbeans tutorial is telling me to do. In my UserFacade:

In my controller:

QUESTION 1: When I am using my managed bean in JSF-pages, everything is working fine. But when I am using straight my UserFacade class from Servlet filter, entityManager em is always NULL. Why is that?

QUESTION 2: What is the best way to implement that? In my case after authentication I check the role in filter class and redirect user to a correct XHTML-page. Now I am trying to fetch user-entity from DB in that filter class using user/loginname as a parameter in managed queries, but as I said em is always null.

QUESTION 3: Is there way to generate methods to facade or controller class from named queries in entity classes in Netbeans?

If I create entityManager in UserFacade class, it is not null anymore and it is working. I would like to understand why it is working in JSF-pages and why is not working if I try to use facade straight without managed bean? Is that even wise and correct solution and way to implement that?

Thank you for helping me!
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!