I have an abstract class that serves as the base class for a lot of my stateless session beans. One of its fields looks like this:
[code]@PersistenceContext
protected EntityManager entityManager;
[/code]
Now I have a concrete SLSB that extends this abstract class. In its ejb-jar.xml, I attempt to override this very, very generic annotation value with something very specific:
[code]<persistence-context-ref>
<description>Persistence context for Foobar EJB.</description>
<persistence-context-ref-name>persistence/FoobarPersistenceContext</persistence-context-ref-name>
<persistence-unit-name>FoobarPersistenceUnit</persistence-unit-name>
<injection-target>
<injection-target-class>mypackage.AbstractStatelessSessionBean</injection-target-class>
<injection-target-name>entityManager</injection-target-name>
</injection-target>
</persistence-context-ref>
[/code]
To test this out, I made a persistence.xml file that is accessible in a .jar file in the .ear in which this concrete EJB lives. I put two persistence units in it just to make sure there was ambiguity in the mix. I made sure one of them is named FoobarPersistenceUnit.
When I run the verifier, it tells me that it can't resolve the persistence unit "[ null ]", which is what it says if I don't do the ejb-jar.xml overriding. That is, it looks to the verifier--I think--like the override isn't there.
When I remove the @PersistenceContext annotation and recompile/re-jar/re-ear and reverify, everything is OK.
That tells me that all my names and all my references are OK (i.e. it's not a case of typos, or incorrect persistence-unit names or something like that). Oh, and incidentally my ejb-jar.xml is marked as metadata-complete: false.
The specification is a little bit vague on the subject of overriding. Shouldn't I be able to override the "unadorned" @PersistenceContext annotation in ejb-jar.xml?
Is this a problem with the verifier, my interpretation of the specification, or both?
Thanks very much,
Laird
[Message sent by forum member 'ljnelson' (ljnelson)]
http://forums.java.net/jive/thread.jspa?messageID=264624