users@glassfish.java.net

RE: Re: Resource Injection

From: Jason Lee <lee_at_iecokc.com>
Date: Tue, 6 Jun 2006 13:24:18 -0500

Hmm. Well, that didn't work for me either (I was using
session-scoped). For what it's worth, I was injecting EMF as, EM is not
thread-safe.

At any rate, here's my ear structure in case this helps anyone help me.
:P

Chronos.ear/
        META-INF/
                persistence.xml
        Chronos.war/
                META-INF/
                WEB-INF/
                        classes/com/iecokc/chronos/test
                                TestBean.class <-- Faces-managed into
which the DAO is wired via faces-config.xml
                        classes/com/iecokc/chronos/model/
                                beans/
                                        Job.class <-- @Entity
                                model/dao/
                                        IChronosDAO.class <-- interface
                                        impl/
                                                ChronosDaoJpaImpl.class
<-- Faces-managed bean with EM injection hopes
                        lib/
                                <bunch of jars>
                        faces-config.xml
                        web.xml
                index.xhtml
                layout.xhtml

The logs make it appear as if the PU is created, as I see a "login
successful" message:

[#|2006-06-06T13:14:20.709-0500|INFO|sun-appserver-pe9.0|oracle.toplink.
essentials.file:/C:/java/glassfish/domains/domain1/applications/j2ee-app
s/Chronos/Chronos_war/WEB-INF/classes/-em|_ThreadID=13;_ThreadName=httpW
orkerThread-4848-0;file:/C:/java/glassfish/domains/domain1/applications/
j2ee-apps/Chronos/Chronos_war/WEB-INF/classes/-em;|login_successful|#]

The only error I get is the NPE when I hit my test web page.

From what I can find on the web, my annotations and xml config are
correct. Am I packaging the app incorrectly (did my layout above even
make sense :) ? I've also tried putting META-INF/persistence.xml in the
WAR to no avail. :|

--
Jason Lee
Programmer/Analyst
-----Original Message-----
From: Craig.McClanahan_at_Sun.COM [mailto:Craig.McClanahan_at_Sun.COM] 
Sent: Tuesday, June 06, 2006 12:08 PM
To: users_at_glassfish.dev.java.net
Cc: users_at_javaserverfaces.dev.java.net
Subject: Re: Resource Injection
Jason Lee wrote:
> I'm trying to get my container (Glassfish) to inject my persistence 
> unit into a faces-managed bean, but I'm not having much luck.  It is 
> my understanding that this should be possible, but I don't see it 
> happening.  Here's my persistence.xml:
For what it's worth, it works fine for me (using either the 5.5 preview 
or 5.5 beta).   The thing I'm doing different, though, is injecting an 
EntityManager instead of an EntityManagerFactory (because I'm injecting
into a request scope backing bean).  You might try that instead.
    @PersistenceUnit
    private EntityManager em;
I'd also scan the server's log file to see if any exceptions are getting
recorded -- might give a clue to why the injection did not work.
> Thanks!
>  
> --
> Jason Lee
> Programmer/Analyst
>
>   
Craig McClanahan
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
For additional commands, e-mail: users-help_at_glassfish.dev.java.net