I am facing a strange behavior that i don't understand. In fact i have a DAO AbstractFacade in which i injected an EntityManager. From this abstract class i derived many subclasses. First the project did'nt work properly et resulted in many exceptions. Then i noticed from error messages that i had a problem with getting the EntityManager to do persistence jobs. That was strange because i got a getter in the abstract class that returns the
entityManager.
public class AbstractFacade<T> {
private EntityManager em;
private Class<T> entityClass;
protected EntityManager getEntityManager() {
return em;
}
public AbstractFacade(Class entityClass){
this.entityClass = entityClass;
}
So i am wondering why is'nt it working in the subclass ? I got an idea to override that method which solved the problem and no more exceptions!
@Stateless
@LocalBean
public class AirportFacade extends AbstractFacade<Airport> implements AirportFacadeLocal{
@PersistenceContext(unitName = "flams_pu")
private EntityManager em;
public AirportFacade(){
super(Airport.class);
}
@Override
public EntityManager getEntityManager(){
return em;
}
So GOOD so far but but i am not satisfiyed because i could'nt figure out why it did'nt work before overriding the getter ??
So please if anyone knows why, let me know and thanks very much.