Meaningless Drivel is fun!*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes @PersistenceContext Injection in SessionBeans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "@PersistenceContext Injection in SessionBeans" Watch "@PersistenceContext Injection in SessionBeans" New topic

@PersistenceContext Injection in SessionBeans

Daniel Jabonete
Ranch Hand

Joined: Apr 01, 2007
Posts: 76
Hi Guyz,

I would like to kindly ask the rules in injecting @PersistenceContext for the EntityManager in a SessionBeans.

I’ve injected the following in my SessionBean, please see below:

In order to hold of the EntityManager but, when I deployed it in my Glassfish it throws the following connection error in the logs:

So I removed the injection above, then deployed again, it throws no error.

Appreciate your help pertaining to these issues. Thanks very much!

Remko Strating
Ranch Hand

Joined: Dec 28, 2006
Posts: 893
It sounds that the dependency injection is not the problem, but the way you're trying to connect to the database. Check your parameters for connecting to the database.

Remko (My website)
SCJP 1.5, SCWCD 1.4, SCDJWS 1.4, SCBCD 1.5, ITIL(Manager), Prince2(Practitioner), Reading/ gaining experience for SCEA,
Deepika Joshi
Ranch Hand

Joined: Feb 24, 2009
Posts: 268
Check persistese.XML, db connection tag.
Daniel Jabonete
Ranch Hand

Joined: Apr 01, 2007
Posts: 76
Hi Guyz,

I' am not sure which database connection you are referring at, or which configurations and where...

But as I dig deeper to this problem, I've found out that the problem was on the Glassfish Resources> JDBC> JDBC Resources> jdbc/__default which point to the "DerbyPool".

I've created Resources> JDBC> Connection Pools> MySqlDs and then point the "jdbc/__default" to "MySqlDs", and voila I'd successfully deployed my EJB with EntityManager injected in my Stateless SessionBean(s).

Now, what are the differences when using "DerbyPool" aside from creating my own (live) connection. and DerbyPool seems not running by default. What about when porting to other Application Server...?

Anyone share some lights pertaining to this topic. Thanks very much!

Don't get me started about those stupid light bulbs.
subject: @PersistenceContext Injection in SessionBeans
Similar Threads
Connecting to oracle through glassfish
hibernate.cfg.xml location for Eclipse project
Runtime Exceptions for JDBC program using Derby Client in Netbeans
Getting error chapter 8 of Ejb 3 in action using glassfish server 2.1
Unable to find database