sessionFactory null when trying to select select in the database

0

Good morning, I'm using Spring and JSF. I want to make a query to the database and return the data of a table, but in the method that I make the search, when calling the sessionFactory, it is coming null. I really could not 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" />
*/
    
asked by anonymous 26.02.2018 / 15:17

1 answer

1

Thanks for the reply, I found the problem. I was forgetting the @ManagedProperty injection ("# {listPlanilhasDao}"). With that it would come null forever.

    
27.02.2018 / 13:18