I used Hibernate session to query data from MySQL. I used JPA EntityManagerFactory to get Hibernate SessionFactory:
@Configuration
public class DatabaseConfig {
@Autowired
private EntityManagerFactory entityManagerFactory;
@Bean
public SessionFactory getSessionFactory() {
if (entityManagerFactory.unwrap(SessionFactory.class) == null) {
throw new NullPointerException("Factory is not a hibernate factory");
}
return entityManagerFactory.unwrap(SessionFactory.class);
}
}
This worked fine with Spring Boot 1.5.x. But when I updated Spring Boot to 2.0.1:
Error creating bean with name 'databaseConfig': Unsatisfied dependency expressed through field 'entityManagerFactory';
What should I do to solve this problem in Spring Boot 2.0.x?