How to disconnect a Hibernate SessionFactory session at Spring boot

I created a spring boot application and I want to handle the Hibernate SessionFactory, so in my service class I can just call the Hibernate SessionFactory as follows:

@Autowired
private SessionFactory sessionFactory;

I found a similar question in stackoverflow, where I need to add the following line in application.properties:

spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate4.SpringSessionContext

but I get this error:

Cannot resolve property 'current_session_context_class' in java.lang.String

How can i solve this?

pom.xml dependencies:

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
    </dependencies>
+4
source share
2 answers

Try enabling HibernateJpaSessionFactoryBean in your Spring configuration.

@Bean
public HibernateJpaSessionFactoryBean sessionFactory() {
    return new HibernateJpaSessionFactoryBean();
}

Take a look: fooobar.com/questions/176517 / ...

Spring , @Configuration @SpringBootApplication ( @Configuration).

+2

2.0, JPA API- . EntityManager EntityManagerFactory , JPA.

Hibernate Session SessionFactory.

SessionFactory sessionFactory = entityManagerFactory.unwrap(SessionFactory.class);
+2

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


All Articles