File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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
 
jQuery in Action, 2nd edition
 
subject: EntityManager is null when I try to use it straight from filter servlet
 
Similar Threads
Greenhorn: JPA entitymanager is null and I don't think is suppose to be?
How to create a Template for EntityManager in a WebApplication
DataTable: No items found error
Need help with design structure and looking up EntityManager and UserTransaction in helper's helper
JPA2.0 CascadeType.ALL doesn't cascade persist