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?
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.