users@glassfish.java.net

RE: Re: createQuery() NPE

From: Jason Lee <lee_at_iecokc.com>
Date: Tue, 6 Jun 2006 17:50:29 -0500

By "package" I meant archive. It's in the META-INF/ directory of the
same archive (.war) that holds the classes in question.
 
Unfortunately, as far as the NPE goes, I don't have much to go on.
Here's all I have from the server logs :
 
[#|2006-06-06T15:14:33.110-0500|INFO|sun-appserver-pe9.0|javax.enterpris
e.system.stream.out|_ThreadID=14;_ThreadName=httpWorkerThread-8080-0;|
java.lang.NullPointerException
        at
com.sun.enterprise.util.EntityManagerWrapper.createQuery(EntityManagerWr
apper.java:525)
        at
com.iecokc.chronos.model.dao.impl.ChronosDaoJpaImpl.getJobs(ChronosDaoJp
aImpl.java:28)
        at com.iecokc.chronos.test.TestBean.getJobs(TestBean.java:26)

I can't use NetBeans, as Eclipse is the corporate standard.

I have Googled, but not found anything of value. Of course, it's likely
that my choice of keywords isn't correct, so I continue to try slightly
different searches, but I'm not having any success thus far.

I had forgotten about the verifier, which pointed out some issues it had
with my persistence.xml, which I though was spec compliant, but I made
the changes anyway, just to be sure. The errors still persisted until I
moved the entity beans, the DAO, and META-INF/persistence.xml to a
separate jar file in the root of the ear, at which point things started
working. I'm confused as to why that would have made a difference. It
is my understanding that it ought to work, but either my understanding
is flawed, or I was missing something fundamental. :|

At any rate, I got it working. Why it works I'll leave to another day.
;)

Thanks for your help.
 
--
Jason Lee
Programmer/Analyst
 
________________________________
From: Ludovic.Champenois_at_Sun.COM [mailto:Ludovic.Champenois_at_Sun.COM] 
Sent: Tuesday, June 06, 2006 3:16 PM
To: users_at_glassfish.dev.java.net
Subject: Re: createQuery() NPE
Jason Lee wrote: 
	Well, I thought I could whip this one on my own, but I'm just
not having a very good day so far. :P  I have the EM now injected
correctly, but when I call  em.createQuery("select j from Job j"); i get
a NPE.  Job is an annotated class (@Entity, @Table, @Id and
Serializable, fwiw) in the same package as the PU file, which also
references the class explicitly.  em.isOpen() returns true, but any
other call on the object results in an NPE.  It has to be something
subtle I'm missing, as some working code we have looks extremely
similar.
Obviously, for such 'subtil' issues, we need much more than 'I get a
NPE' description...
Maybe you could 'google' this exception to see if it is mentioned
somewhere.
Using tools like NetBeans 5.5 can also avoid many common mistakes. 
You can also run the verifier tool to track advanced errors
(.../bin/verifier(.bat/.sh) archivename).  The verifier tool is also in
NetBeans 5.5.
I am not sure why you say 'same package as the PU file...' The PU file
should not be in a package, but in in a META-INF dir.
Ludo
	  I'm just having trouble tracking it down.  Anyone have any
quick hints off the top of their head?  Thanks!
	 
	--
	Jason Lee
	Programmer/Analyst