I\'m running Glassfish 3.1-SNAPSHOT as of today (2010-11-12).
I\'m using the embedded EJBContainer.
On the classpath, as reported by the EJBContainer, I have
I faced the same problem. The error was in the name of one of my unitName
unitName="PUname error in one of my classes"
If by mistake you put @PersistenceContext(name="cx") instead of @PersistenceContext(unitName="cx") you get the same error with everything else working.
This one is a combination of weird behavior and pilot error.
First, the pilot error.
The particular JUnit test case I was looking at was that of a colleague, and it was named as though it were an EJB itself, following our internal naming convention. This is probably a cut and paste error on my colleague's part.
I mention that because every time I opened the file I stared at it as though it itself were an EJB.
But of course it is not an EJB.
However, mysteriously, there is a @PersistenceContext
annotation in there, and an EntityManager
, which is unused. The persistence context has an attribute of--you guessed it--unitName="cx"
.
So the strange behavior is that somewhere in between the old EJB container, which ran this test case fine, and now, the EJB container began treating this non-EJB, non-special class as a valid target for @PersistenceContext
injection. Perhaps this test case is being treated as a managed bean, but I was under the impression that managed beans in a non-CDI environment had to be annotated as such.
Anyhow, once I removed this spurious @PersistenceContext
annotation, everything worked fine.