Olá, pessoal.
Preciso injetar 2 dependências da camada DAO em um bean de cadastro.
O bean em questão é referente a classe funcionários, acontece que nesse bean tenho um método para listar setores.
Acredito que há um confilto no momento de injetar os daos, pois um é genérico. O outro, funcionarioDAO, estende do primeiro.
Obs: Injetando apenas 1 DAO consegui persistir de boa.
Segue minhas classes:
O DAO genérico:
[code]package br.com.techfor.nasa.dao;
import java.io.Serializable;
import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;
@Repository
public class GenericDAOImpl<T, PK> extends HibernateDaoSupport implements
GenericDAOInterface<T, PK> {
private Class<T> classe;
@Autowired
public GenericDAOImpl(SessionFactory sessionFactory) {
setSessionFactory(sessionFactory);
}
@Override
public void saveOrUpdate(T bean) {
getHibernateTemplate().saveOrUpdate(bean);
}
@Override
public void update(T bean) {
getHibernateTemplate().update(bean);
}
@Override
public void delete(T bean) {
getHibernateTemplate().delete(bean);
}
@Override
public T getBean(PK pk) {
return getHibernateTemplate().get(this.classe, (Serializable) pk);
}
@Override
public List<T> getBeans() {
return (List<T>) getHibernateTemplate().loadAll(this.classe);
}
}
[/code]
FuncionarioDAO
package br.com.techfor.nasa.dao;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;
import br.com.techfor.nasa.model.Funcionario;
@Repository
public class FuncionarioDAOImpl extends GenericDAOImpl<Funcionario, Long>
implements FuncionarioDAOInterface {
@Autowired
public FuncionarioDAOImpl(
@Qualifier("sessionFactory") SessionFactory sessionFactory) {
super(sessionFactory);
}
}
Meu Bean
package br.com.techfor.nasa.mb;
import java.util.ArrayList;
import java.util.List;
import javax.faces.model.SelectItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import br.com.techfor.nasa.dao.FuncionarioDAOInterface;
import br.com.techfor.nasa.dao.GenericDAOInterface;
import br.com.techfor.nasa.model.Funcionario;
import br.com.techfor.nasa.model.Setor;
@Controller("funcionarioMB")
public class FuncionarioMB {
private Funcionario funcionario;
private FuncionarioDAOInterface funcionarioDAO;
private GenericDAOInterface<Setor, Integer> genericDAO;
private List<Setor> listSetores;
private List<SelectItem> listItemSetores;
public void setFuncionario(Funcionario funcionario) {
this.funcionario = funcionario;
}
@Autowired
public void setFuncionarioDAO(FuncionarioDAOInterface funcionarioDAO) {
this.funcionarioDAO = funcionarioDAO;
}
@Autowired
public void setGenericDAO(GenericDAOInterface<Setor, Integer> genericDAO) {
this.genericDAO = genericDAO;
}
public Funcionario getFuncionario() {
if (this.funcionario == null) {
this.funcionario = new Funcionario();
this.funcionario.setSetor(new Setor());
}
return this.funcionario;
}
public void saveOrUpdate() {
this.funcionarioDAO.saveOrUpdate(this.funcionario);
}
public void setListItemSetores(List<SelectItem> listItemSetores) {
this.listItemSetores = listItemSetores;
}
public List<Setor> getListSetores() {
if (this.listSetores == null) {
this.listSetores = genericDAO.getBeans();
}
return listSetores;
}
public void setListSetores(List<Setor> listSetores) {
this.listSetores = listSetores;
}
public List<SelectItem> getListItemSetores() {
if (this.listItemSetores == null) {
this.listItemSetores = new ArrayList<SelectItem>();
for (Setor setor : this.getListSetores()) {
this.listItemSetores.add(new SelectItem(setor.getId(), setor
.getNome()));
}
}
return listItemSetores;
}