Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Hibernate 5中自动连线SessionFactory?_Hibernate_Spring Boot_Kotlin_Hibernate 5.x - Fatal编程技术网

如何在Hibernate 5中自动连线SessionFactory?

如何在Hibernate 5中自动连线SessionFactory?,hibernate,spring-boot,kotlin,hibernate-5.x,Hibernate,Spring Boot,Kotlin,Hibernate 5.x,我尝试autowire SessionFactory,但出现以下错误: APPLICATION FAILED TO START *************************** Description: Field bookRepository in com.test.app.BookService required a bean named 'entityManagerFactory' that could not be found. 我在这里介绍autowire SessionF

我尝试autowire SessionFactory,但出现以下错误:

APPLICATION FAILED TO START
***************************

Description:

Field bookRepository in com.test.app.BookService required a bean named 'entityManagerFactory' that could not be found.
我在这里介绍autowire SessionFactory:

@Service
class TestClass{
    @Autowired
    lateinit var sessionFactory: SessionFactory
......
}
这是我的配置类:

@Configuration
class SpringConfig {
    @Bean
    fun sessionFactory(emf: EntityManagerFactory): HibernateJpaSessionFactoryBean {
        val fact = HibernateJpaSessionFactoryBean()
        fact.entityManagerFactory = emf
        return fact
    }
}
我试着这样做:

@Configuration
class SpringConfig {
    @Bean
    fun sessionFactory(): HibernateJpaSessionFactoryBean {
        return HibernateJpaSessionFactoryBean()
    }
}
My application.yml:

spring:
    datasource:
        driver-class-name: org.postgresql.Driver
        url: datasource_url
        password: password
        username: username
        hikari:
            maximum-pool-size: 5
    jpa:
        properties:
            hibernate:
                jdbc:
                    batch_size: 20
                current_session_context_class: org.springframework.orm.hibernate5.SpringSessionContext
休眠版本:5.4.1


Spring boot版本:2.0.0.M3

为什么需要一个
SessionFactory
?只需插入一个
EntityManager
即可使用JPA而不是普通的Hibernate。这基本上也是您的异常情况告诉您的,它抱怨的是
EntityManagerFactory
而不是
SessionFactory
@M.Deinum我处理大量数据,需要提高性能。我需要会话方法saveorupdateth,它不会提高您的性能。正确的批处理技术将使我尝试批处理,但仍然不够。所以我想尝试保存或更新你尝试了什么?如前所述,saveOrUpdate不会帮助您信任我。正确的批处理技术(清除和刷新实体管理器)将起作用。为什么需要
会话工厂
?只需插入一个
EntityManager
即可使用JPA而不是普通的Hibernate。这基本上也是您的异常情况告诉您的,它抱怨的是
EntityManagerFactory
而不是
SessionFactory
@M.Deinum我处理大量数据,需要提高性能。我需要会话方法saveorupdateth,它不会提高您的性能。正确的批处理技术将使我尝试批处理,但仍然不够。所以我想尝试保存或更新你尝试了什么?如前所述,saveOrUpdate不会帮助您信任我。适当的批处理技术(清除和刷新实体管理器)将起作用。