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

Injecting PersistenceContext

 
satish bodas
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Am trying to inject a persistenceContext in Jboss deployed app

However I keep getting a null pointer exception - the PersistenceContext is not being injected .

Am trying to inject the PC in a non ejb object

Would this be the cause ?

Can it only be injected in ejbs ?

Thanks ,
~satish
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which version of JBoss?
 
satish bodas
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
using Jboss 4.2.2 GA

Thanks ,
~satish
 
satish bodas
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On deploying a session bean ( stateless ) and then injecting a PersistenceContext in the session bean works for me .


So to inject PC is it only possible when using Session beans ?

If yes - than how do I make use of a container managed Entity Manager minus the injection ?

Thanks ,
~satish
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The @PersistenceContext injection is only supported in managed objects (EJBs, servlets etc...). Where are you injecting this PersistenceContext? In JBoss-4.2.x the injection of PersistenceContext is probably not supported in web tier too (because 4.2.x is a J2EE1.4 server with EJB3 patch).

If yes - than how do I make use of a container managed Entity Manager minus the injection ?


A JNDI lookup will give you the persistence context. See "3.4.2. Referencing from Global JNDI" at EntityManager configuration in JBoss
 
satish bodas
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jaikiran for the inputs .

In my sample test that I am doing - I am invoking a jsp from browser

The jsp is creating an instance of a simple Java Class that I call as the "delegate" .
The delegate is being injected with the PC

I know this is not good design where JSP is starting the invocation - but I just wanted to play around with ejb's

Since my " delegate " is not managed - it too cannot make use of DI ?

Here is the sample code used :
This is the JSP


This is the "delegate" :


Thanks Jai for the inputs and help.
~satish
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since my " delegate " is not managed - it too cannot make use of DI ?


The application server will not scan this class since its not managed. So yes, you cannot inject it here.
 
satish bodas
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jaikiran for helping me out .

Regards,
~satish
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic