JBoss Community

EntityManager in a @Service

created by Andrea Polci in EJB3 - View the full discussion

I'm trying to write a @Service that need access to an EntityManager.

I'll use the service throw the JMX console.

 

The problem is that I can't find a way to inject the entity manager into the service.

 

This is a simplified version of my code:

 

public inteface MyManager {
   public void method(String argument);
}
 
@Service(objectName="xxxx:service=myservice")
public class MyMBean implements MyManager {
 
  @PersistenceContext(unitName="my-persistence-unit")
  private EntityManager em;
 
  public void method(String argument) {
    // code using em
  }
}

 

 

The service get exposed throgh the jmx console, but em is always null.

 

I tried to @Inject an entity manager configured in a @Producer, but i get the same result.

 

I'm using JBoss AS 6.0.0 Final

 

Thanks for any help,

Andrea

Reply to this message by going to Community

Start a new discussion in EJB3 at Community