aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes injecting @PersitenceContext Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "injecting @PersitenceContext " Watch "injecting @PersitenceContext " New topic
Author

injecting @PersitenceContext

Saathvik Reddy
Ranch Hand

Joined: Jun 03, 2005
Posts: 228
Hi,

Can we inject @PersitenceContext in non managed objects? Injecting @PersitenceContext works fine in EJB and Servlets but when i try to inject it in a regular java class within the .ear file i am getting null pointer exception. Could some one clarify me about this?

Thanks,
Srikanth.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9318
    
109

The @PersistenceContext is injected by the server. The server only scans those classes whose lifecycle is managed by the server (example: servlet, EJB etc...). So if you are injecting it in a class which is not managed by the server, then the injection will not happen.


[My Blog] [JavaRanch Journal]
Saathvik Reddy
Ranch Hand

Joined: Jun 03, 2005
Posts: 228
Jaikiran,

I am trying to create entity manager factory in my web application as


I have persistence.xml file in EAR/META-INF

I get exception couldn't find persistence unit. How to create entity manager in a non managed class in web application?

Does my question make any sense?

Thanks,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: injecting @PersitenceContext
 
Similar Threads
Ways to get hold of RemoteInterface
Using Resource Bundle in XML Config file
Stateful session bean + @Remove [EJB3]
What to choose, daoFactory or a SpringUtil from ZK?
@Resource annotation question