泛型错误 - 找不到符号类

时间:2013-05-04 20:58:56

标签: java compiler-errors

这是我的第一个问题。我是初学者: - )

我有通用DAO(CrudDao):

public class CrudDAO<T> {

  @PersistenceContext
  protected EntityManager em;

  private Class<T> classePersistencia;

  public CrudDAO() {
    this.setClassePersistencia((Class<T>) ((ParameterizedType)
        getClass().getGenericSuperclass()).getActualTypeArguments()[0]);
  }

  public T salvar(T entity) {
    em.persist(entity);
    return entity;
  }

  public T alterar(T entity) {
    return em.merge(entity);
  }

  public void excluir(T entity) {
    em.remove(entity);
  }

  public T buscarPorId(Long id) {
    return (T) em.find(getClassePersistencia(), id);
  }

  public List<T> buscarTodos(){
    return em.createQuery("from " + getClassePersistencia().getName()).getResultList();
  }

  /*Getter e Setter*/

  public Class<T> getClassePersistencia() {
    return classePersistencia;
  }

  public void setClassePersistencia(Class<T> classePersistencia) {
    this.classePersistencia = classePersistencia;
  }
}

我有DiasService

public class DiasService extends CrudDAO<Dias> implements IdiasService {

  @Transactional(readOnly = true)
  public Dias buscaPorId(Long id) {
    return (Dias) super.buscarPorId(id);
  }

  @Transactional(readOnly = false)
  public Dias salvar(Dias dia) {
    return (Dias) super.salvar(dia);
  }

  @Transactional(readOnly = false)
  public Dias alterar(Dias dia) {
    return (Dias) super.alterar(dia);
  }

  @Transactional(readOnly = false)
  public void excluir(Dias dia) {
    super.excluir(dia);
  }

  @Transactional(readOnly = true)
  public List<Dias> buscaPorPeriodo(Date inicio, Date fim) {
    return null;
  }

  @Transactional(readOnly = false)
  public List<Dias> buscaTodos() {
    return super.buscarTodos();
  }

  @Transactional(readOnly = true)
  public Dias buscaPorData(Date data) {
    return null;
  }

}

当我编译时,我得到错误:

cannot find symbol class CrudDAO

怎么了?

1 个答案:

答案 0 :(得分:0)

这两个类来自不同的包吗?如果是,你是否导入了CrudDAO?

如果它们位于同一个软件包中,请提供有关您所获得的编译器错误的更多详细信息。