0
Good morning,
I’m using Spring and JSF. I wanted to query the database and return the data from a table, but in the method I do the search, when calling sessionFactory, it is null. I really couldn’t find the problem.
/*classe DAO*/
package br.com.racionalgames.pta.dao;
import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.Transactional;
import br.com.racionalgames.pta.model.UploadFiles;
@Repository("ListPlanilhasDao")
@Transactional
@EnableTransactionManagement
public class ListPlanilhasDaoImpl implements ListPlanilhasDao {
@SuppressWarnings("unchecked")
@Override
public List<UploadFiles> getListPlanilha() throws Exception {
List<UploadFiles> lista = null;
String sql = "SELECT * FROM pta.criterios_multiskill";
try {
lista = sessionFactory.getCurrentSession().createSQLQuery(sql).list();
} catch (Exception e) {
System.out.println("Erro no DAO: " + e);
}
return (List<UploadFiles>) lista;
}
@Autowired
private SessionFactory sessionFactory;
public SessionFactory getSessionFactory() {
return sessionFactory;
}
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
}
*spring-config.xml <bean id="ListPlanilhasDao" class="br.com.racionalgames.pta.dao.ListPlanilhasDaoImpl" />
*/
You are creating the DAO bean manually, correct? How are you building the Session Factory? Why doesn’t it pass as a parameter to the DAO bean you are creating? What you went through is not having the scan to build context, difficult to know how your application is.
– Bruno César