How to get an instance of SessionFactoryImplementor?

Like the title: how can I get an instance SessionFactoryImplementor? What I hacked in the code:

SessionFactoryImplementator  sfi
    = (SessionFactoryImplementator) session.getSessionFactory();

I don't really like this, and I was wondering if there was any other, more elegant way to get the developer instance.

+3
source share
3 answers

I did not find a public class that returns a constructor, so your approach is fine. (For example, see here , when using> returned)

+3
source

What about:

SessionFactoryImplementor sfi = (SessionFactoryImplementor) ctx.getBean("sessionFactory");
+1
source

, , ... SessionFactoryImplementator sfi = (SessionFactoryImplementator) session.getSessionFactory(); : SessionFactoryImplementor sfi = (SessionFactoryImplementor) ctx.getBean("sessionFactory"); , Spring, , , Spring3/4 SessionFactoryBean "openSession" .. ( ), , Spring ApplicationContext , " " SessionFactory, Hibernate SessionFactory ( AoP , .)

If you know that there is only one Hibernate SessionFactory in your "appCtx", then an even better way: appCtx.getBean(org.hibernate.SessionFactory.class);

0
source

Source: https://habr.com/ru/post/1772463/


All Articles