Skip to main content

Posts

Showing posts with the label SessionFactory

SpringBoot : How to use & configure SessionFactory Bean

Points To Remember Add the SessionFactory  bean in the Application class. Add the Current Session Context class in application.properties. Use the SessionFactory using  @Autowired  annotation. How to Configure & Use SessionFactory Bean Add the following to the Main Application class or Configuration class. view plain copy to clipboard print ? @Bean    public  SessionFactory sessionFactory(HibernateEntityManagerFactory hemf){        return  hemf.getSessionFactory();   }   @Bean public SessionFactory sessionFactory(HibernateEntityManagerFactory hemf){ return hemf.getSessionFactory(); } Add the following line in application.properties spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate4.SpringSessionContext Now you can use the Session Factory in your code as follows. view plain copy to clipboard print ? class  Sample {   ...