aspose file tools*
The moose likes Object Relational Mapping and the fly likes EntityManager is null when I try to use it straight from filter servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "EntityManager is null when I try to use it straight from filter servlet" Watch "EntityManager is null when I try to use it straight from filter servlet" New topic
Author

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

Sami Nurmi
Greenhorn

Joined: Mar 13, 2012
Posts: 2
Hi!

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!
Sami
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EntityManager is null when I try to use it straight from filter servlet