В сессию приходит null, уже запутался в конец.
interface DAO:
public interface HumanDao {
List<Human> getAll() throws DaoException;
List<Human> getAllById(long id) throws DaoException;
}
impl interface:
public class HumanDaoImplHibernate implements HumanDao{
private SessionFactory sesionFactory;
public void setSesionFactory(SessionFactory sesionFactory) {
this.sesionFactory = sesionFactory;
}
@SuppressWarnings("unchecked")
@Override
public List<Human> getAll() throws DaoException {
try{
Session session = this.sesionFactory.getCurrentSession();// here come is null!
List<Human> personsList = session.createQuery("from Human").list();
return personsList;
}catch(NullPointerException e){
System.out.println("cause: "+e.getCause());
}
return null;
}
@Override
public List<Human> getAllById(long id) throws DaoException {
// TODO Auto-generated method stub
return null;
}
}
Junit test:
public class HumanHibTest {
@Test
public void getAll() throws DaoException{
HumanDaoImplHibernate hib = new HumanDaoImplHibernate();
hib.getAll();
}
}
Тестом дергаю метод HumanDaoImplHibernate.java и при детальном изучении SessionFactory в дебаге приходит null:

В чем ошибка, где корень зла? Помогите плиз.
Валидатор не пропустил остальной код: hibernate.cfg.xml:
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.connection.password">123</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/test</property>
<property name="connection_pool_size">1</property>
<property name="hbm2ddl.auto">create</property>
<property name="show_sql">true</property>
<mapping class="com.datapeople.bean.Address"/>
<mapping class="com.datapeople.bean.Human"/>
<mapping class="com.datapeople.bean.StreetDirectory"/>
</session-factory>
Hibernate instance:
public class HibernateCongigurator {
private static HibernateCongigurator instance;
private SessionFactory sesionFactory;
public static HibernateCongigurator getInstance() {
if (instance == null) {
synchronized (HibernateCongigurator.class) {
if (instance == null) {
instance = new HibernateCongigurator();
}
}
}
return instance;
}
private HibernateCongigurator() {
sesionFactory = new Configuration().configure().buildSessionFactory();
}
public SessionFactory getConfiguration() {
return sesionFactory;
}
}
HumanDaoImplHibernate.sesionFactoryприсваивается только вsetSesionFactory, который нигде не вызывается. – zRrr Oct 26 '17 at 10:25