I am working on spring boot 2.5 and Hibernate 5 but my getSession always comes as null. Below is the code I have. I have googled but the answers are for spring boot up to version 2.
spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate5.SpringSessionContext
and
import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
@Repository
@Transactional
public class ABC{
@Autowired
private EntityManager entityManager;
private Session getSession() {
//below line always return null/null pointer for me
return entityManager.unwrap(Session.class);
}
public String gettingSession() {
getSession();
//I am trying to run queries like below after i get the session.
// List<EMP> employee=(List<EMP>) getSession().createQuery("from EMP").list();
return "hello";
}
}
I tried below links and getting same null/null pointer: