File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "@PersistenceContext Injection in SessionBeans" Watch "@PersistenceContext Injection in SessionBeans" New topic
Author

@PersistenceContext Injection in SessionBeans

Daniel Jabonete
Ranch Hand

Joined: Apr 01, 2007
Posts: 78
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!

Cheers!
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: 78
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!

Cheers!
 
jQuery in Action, 2nd edition
 
subject: @PersistenceContext Injection in SessionBeans