1
GenericDao를 구현 중입니다. 나는 getAll()과 getById (Long id)라는 두 가지 메소드에 문제가있다. 엔티티 클래스는 null 값을 갖는다. 클래스가 설정되지 않은 것 같습니다. 어떻게이 문제를 해결할 수 있습니까?GenericDao, Class <T>이 null입니다.
@Repository
public class GenericDaoImpl<T> implements GenericDao<T> {
private Class<T> clazz;
@Autowired
SessionFactory sessionFactory;
public void setClazz(final Class<T> clazzToSet) {
this.clazz = clazzToSet;
}
public T getById(final Long id) {
return (T) this.getCurrentSession().get(this.clazz, id);
}
public List<T> getAll() {
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(
this.clazz);
return criteria.list();
}
protected final Session getCurrentSession() {
return this.sessionFactory.getCurrentSession();
}
}
PersonDao
public interface PersonDao extends GenericDao<Person> { }
PersonDaoImpl
@Repository("PersonDAO")
public class PersonDaoImpl extends GenericDaoImpl<Person> implements PersonDao {}
서비스 :
@Service
public class PersonServiceImpl implements PersonService {
@Autowired
private PersonDao personDao;
@Transactional
public List<Person> getAll() {
return personDao.getAll();
}
@Transactional
public Person getById(Long id) {
return personDao.getById(id);
}
}
감사합니다. – kxyz
@kxyz 기꺼이 도와 드리겠습니다. –