Quantcast
Channel: zeroturnaround.com » All Posts
Viewing all articles
Browse latest Browse all 2540

Spring boot and Hibernate session context

$
0
0

This is my SpringBoot app with @Bean configuration for SessionFactory:

@SpringBootApplication
public class BooksListApplication {

	public static void main(String[] args) {
		SpringApplication.run(BooksListApplication.class, args);
	}

	@Bean
	public SessionFactory sessionFactory(HibernateEntityManagerFactory hemf) {
		return hemf.getSessionFactory();
	}
}

my configuration:

spring.datasource.url= jdbc:postgresql://localhost:5432/books
spring.datasource.username=postgres
spring.datasource.password=123123
spring.jpa.hibernate.ddl-auto=create-drop

spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL9Dialect
spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate5.SpringSessionContext

And my Dao class:

public abstract class AbstractDao<T> implements CrudRepository<T, Long> {

    @Autowired
    private SessionFactory sessionFactory;

    @Override
    @Transactional
    public <S extends T> S save(S entity) {
        sessionFactory.getCurrentSession().save(entity);
        return entity;
    }

...

}

save() method ends up with org.hibernate.HibernateException: No CurrentSessionContext configured!

because configuration:

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

is never loaded. It works fine with IntelliJ defult deburger. Problem exists onlny while running with JRebel debuger.

Property should be loaded in org.hibernate.internal.SessionFactoryImpl:1219 from hibernate 5.0.12 but it loads as null


Viewing all articles
Browse latest Browse all 2540

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>