Spring boot and Hibernate session context

ZeroTurnaround Homepage Forums JRebel Support Spring boot and Hibernate session context

Tagged: , ,

This topic contains 0 replies, has 1 voice, and was last updated by  Krzysztof Majewski 2 months, 2 weeks ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #62653

    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 1 post (of 1 total)

You must be logged in to reply to this topic.