0
votes

I want a DAO that extends from a generic DAO like this:

public abstract class DAO<T> implements Serializable{

private Class<T> entityClass;

public DAO(){

}

public void setClass(Class<T> entityClass){
    this.entityClass=entityClass;
} 

protected abstract EntityManager getEntityManager();

and the CDI bean that extends from the generic class and is injected in an EJB

@Named("daoImpl")
@RequestScoped
public class DAOImpl extends DAO implements Serializable{


@PersistenceContext(unitName = "pruebaEJBPU")
private EntityManager em;

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


public DAOImpl() {

    setClass(User.class);
}

I have to use the setClass method because I want to inject this bean in an EJB and it can´t have an arg-constructor.

This way works but it throws a warning that i can't avoid: WARNING: The following warnings have been detected: WARNING: Parameter 1 of type java.lang.Class from public void p1.dao.setClase(java.lang.Class) is not resolvable to a concrete type.

Is there another way to extend a CDI bean from a generic class or avoid the warnings? If i use an EJB like Netbeans does, all is fine but i don't want to use an EJB for a DAO. If i don't use a CDI bean, how can i inject a simple DAO in an EJB?

1
What IDE is giving you this warning? I don't get it in NB 8.0kolossus
NB 8.0 with Glassfish 4.0develop4132

1 Answers

0
votes

I think this warning comes up since your generic DAO is parameterized but your concrete implementation of the DAO doesn't specify a parameter type. Add the type to your DAOImpl class declaration an you should be fine.