On Aug 19, 2008, at 3:06 PM, ericp56 wrote:
@PersistenceContext(unitName = "ctimssql")
EntityManager em;
dumb question... this annotated field is in an ejb class?
Whoops! I moved this code to another class. However, adding the @EJB
annotation didn't help. I'm sorry, but I'm still learning a lot of
this.
Am I missing something elementary?
@EJB is the annotation used for getting an EJB injected into your EJB,
Servlet, etc. To make something an EJB one of the two have to happen:
a. must be annotated with @Stateless, @Stateful, or @MessageDriven
b. must be declared via an <session> or <message-driven-bean>
(subelements <ejb-name> and <ejb-class> are required)
We will search for annotations in the bean class of your session bean
or message-driven bean. Only the bean class and its parent classes
are searched for injection related annotations (@Resource, @EJB,
@PersistenceContext, @PersistenceUnit), interfaces and any other
classes are not searched.
When the container instantiates a bean class, the container does
injection, when this happens is different for each bean type. If you
instantiate your bean class via "new MyBean()", no injection.
Here's a good example of all the moving parts:
http://openejb.apache.org/3.0/injection-of-entitymanager-example.html
If you still need a bit more help, post your bean code (can leave the
methods off) and your ejb-jar.xml (if you have one).
-David