Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • Al Hobbs
  • salvin francis

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

Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic