0 Replies Latest reply on Sep 18, 2014 9:22 AM by claudinei

    No EJB found with interface of type when not using @Local

    claudinei

      I have the following structure:

       

      BaseDAO:

       

          @Stateful
          public class BaseDAO<T> {
        
              @PersistenceContext(unitName = Constant.PU)
              private transient EntityManager em;
        
              private final Class<T> type;
        
              @SuppressWarnings("unchecked")
              public BaseDAO() {
                  type = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
            
               //getters/setters
      
              }
      
      
      

       

      AbstractDAO:

       

              public interface AbstractDAO<T extends Serializable, K> {
            
                  void save(T entity) throws ObjectEmptyException, FieldInvalidException, ObjectExistsException;
        
                  //others CRUD methods
          }
      
      
      

       

      AbstractDAOImpl:

       

          @Stateful
          public abstract class AbstractDAOImpl<T extends Serializable, K> extends BaseDAO<T> implements AbstractDAO<T, K> {
        
              /**
               * Instância para o log4j.
               */
              private static final Logger LOGGER = Logger.getLogger(AbstractDAOImpl.class);
        
              @Override
              public void save(final T entity) throws ObjectEmptyException, FieldInvalidException, ObjectExistsException {
                  getEm().persist(entity);
              }
        
              //Others CRUD methods
          }
      
      
      

       

      Then the DAOs:

       

         public interface TaxDAO extends AbstractDAO<Tax, Long> {
        
          }
      
      
      

       

      Impl:

       

          @Stateless
          @Local(TaxDAO.class)
          public class TaxDAOImpl extends AbstractDAOImpl<Tax, Long> implements TaxDAO {
        
          //Implementations Go here
        
          }
      
      
      

       

      When I use @EJB in myService like this:

       

          @EJB
          private TaxDAO taxDAO;
      
      
      

       

      Without @Local in DAO class I got this error in Wildfly 8.1:

       

         Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS014544: No EJB found with interface of type 'br.com.zzz.erp.ejb.dao.domain.TaxDAO' for binding br.com.zzz.erp.ejb.service.domain.impl.TaxServiceImpl/taxDAO"}

       

      When setting annotation @Local in the DAO all works, but the others DAOs with the same code structure in project does not uses Local and works too, only newly created DAOs have this problem.

      Why this happens there is some container limit?

      The good practice is to always annotate @Local?