从Jhipster访问SessionFactory

从Jhipster访问SessionFactory,jhipster,Jhipster,Jhipster基于Spring boot,如何从Jhipster中的服务访问Hibernate SessionFactory。我想执行原始SQL查询,因此需要创建会话。createSQLQuery。。。 我注意到EntityFactory在CacheConfiguration中使用,但如果我尝试将其作为bean注入到我的服务中,我会得到一个NullPointer异常 谢谢, 好的,我知道了。我们只需要补充一点 @PersistenceContext EntityManager entityMa

Jhipster基于Spring boot,如何从Jhipster中的服务访问Hibernate SessionFactory。我想执行原始SQL查询,因此需要创建会话。createSQLQuery。。。 我注意到EntityFactory在CacheConfiguration中使用,但如果我尝试将其作为bean注入到我的服务中,我会得到一个NullPointer异常

谢谢,
好的,我知道了。我们只需要补充一点

@PersistenceContext
EntityManager entityManager;

protected Session getCurrentSession()  {
    return entityManager.unwrap(Session.class);
}
在服务班。 然后,在方法中,只需创建hibernate会话:

Session session = getCurrentSession();
我的想法是,我想在服务的构造函数中创建Hibernate会话