mardi 16 juin 2015

EJB injection not working in different classes

I have tried to inject an Entity EJB(Facade and entity from MySQL database) but it doesn't work depending on the class it is in. I use a Rest webService and it work in the webService class. I use a multi layered architecture and I don't want my EJB to be injected in this webService.

So, this is the @Stateless facade :

public class ActivityEntityFacade extends AbstractFacade<ActivityEntity> {
@PersistenceContext(unitName = "persistance")
private EntityManager em;

@Override
protected EntityManager getEntityManager() {
    return em;
}

public ActivityEntityFacade() {
    super(ActivityEntity.class);
}

}

this is the rest webService method working with EJB :

@EJB
private ActivityEntityFacade activityfacade;

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{date}")
public List<ActivityEntity> activities(@PathParam("date") String date){
    List<ActivityEntity> activityList = activityfacade.findAll();
    return activityList;
}

And this is my activityManager which is supposed to work with the EJB and supposed to return this List to another layer :

public class ActivityManager implements Serializable, IActivity {

@EJB
private ActivityEntityFacade activityfacade;

public ActivityManager(){
}

public List<ActivityEntity> selectAll(){
    return  activityfacade.findAll();
}

}

This snipet return nullPointerException on the activityEntityFacade. Have you any idea why it doesn't work in this case ?

Aucun commentaire:

Enregistrer un commentaire