Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

injecting @PersitenceContext

 
Saathvik Reddy
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Saathvik Reddy
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic