• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Injecting PersistenceContext

 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which version of JBoss?
 
satish bodas
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jaikiran for helping me out .

Regards,
~satish
 
I knew I would regret that burrito. But this tiny ad has never caused regrets:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic