Spring boot Kotlin,SpringBoot(JPA)针对多个存储库的事务性持久性问题

Spring boot Kotlin,SpringBoot(JPA)针对多个存储库的事务性持久性问题,spring-boot,kotlin,jpa,liquibase,Spring Boot,Kotlin,Jpa,Liquibase,我遇到了一个问题,无法将多个实体持久化到它们各自的存储库中。我做错了什么???我能够坚持第一个实体,但不能坚持第二个实体。为什么会这样 助手类: @Component class Helper @Autowired constructor( private val requestRepository: RequestRepository, private val exchangeRateRepository: ExchangeRateRepository,

我遇到了一个问题,无法将多个实体持久化到它们各自的存储库中。我做错了什么???我能够坚持第一个实体,但不能坚持第二个实体。为什么会这样

助手类:

@Component
class Helper @Autowired constructor(
        private val requestRepository: RequestRepository,
        private val exchangeRateRepository: ExchangeRateRepository,
        private val exchangeRateResultRepository: ExchangeRateResultRepository,
        private val responseRepository: ResponseRepository
) {

    fun processClientExchangeRateResponses(base: String, listSymbols: List<String>, clientResponses: List<ClientExchangeRateResponse>) {
        requestRepository.save(Request("Test", "Test"))
        responseRepository.save(Response(10.0, "Test", 12, 12, "Hello"))

    }
}
响应实体:

@Entity
@Table(name = "responses")
class Response(
        private val responseTime: Double,
        private val currencyType: String,
        private val exchangeId: Long,
        private val requestId: Long,
        private val responseObject: String
) {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "native")
    @GenericGenerator(name = "native", strategy = "native")
    @Column(name = "id", updatable = false, nullable = false)
    val id: Long = 0

    @CreationTimestamp
    @Column(name = "created_at", nullable = false, columnDefinition = "DATETIME")
    private val createdAt: ZonedDateTime? = getCurrentDateTime()

    @CreationTimestamp
    @Column(name = "updated_at", nullable = false, columnDefinition = "DATETIME")
    private val updatedAt: ZonedDateTime? = getCurrentDateTime()
}
请求存储库

@Repository
interface RequestRepository : JpaRepository<Request, Long>

@Repository
interface ResponseRepository : JpaRepository<Response, Long>
@存储库
接口请求存储库:JpaRepository
反应性

@Repository
interface RequestRepository : JpaRepository<Request, Long>

@Repository
interface ResponseRepository : JpaRepository<Response, Long>
@存储库
接口响应存储:JpaRepository
主要类别:

@EnableScheduling
@SpringBootApplication
class RatesApplication

    fun main(args: Array<String>) {
        runApplication<RatesApplication>(*args)
    }
@EnableScheduling
@SpringBoot应用程序
等级税率申请
趣味主线(args:Array){
运行应用程序(*args)
}
POM文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>globee</groupId>
    <artifactId>rates</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>rates</name>
    <description>Rates</description>

    <repositories>
        <repository>
            <id>jcenter</id>
            <url>https://jcenter.bintray.com/</url>
        </repository>
    </repositories>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>11</java.version>
        <maven.test.plugin.version>2.22.2</maven.test.plugin.version>
        <kotlin.version>1.3.72</kotlin.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-jpa -->
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
            <version>2.3.4.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
            <version>2.2.2.RELEASE</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.6</version>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.module</groupId>
            <artifactId>jackson-module-kotlin</artifactId>
        </dependency>

        <!--
         Encountered some problems with this maven dependency. See the following two links for this solution
         https://github.com/ascclemens/khttp and
         https://khttp.readthedocs.io/en/latest/user/install.html#jitpack &ndash;&gt;
     -->
        <dependency>
            <groupId>khttp</groupId>
            <artifactId>khttp</artifactId>
            <version>1.0.0</version>
        </dependency>

        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-reflect</artifactId>
        </dependency>

        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-stdlib-jdk8</artifactId>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.liquibase/liquibase-core -->
        <dependency>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-core</artifactId>
            <version>1.9.5</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.13.3</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql.version}</version>
        </dependency>

    </dependencies>

    <build>
        <sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
        <testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                        <configuration>
                            <mainClass>globee.RatesApplication</mainClass>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- https://mvnrepository.com/artifact/org.liquibase/liquibase-maven-plugin -->
            <plugin>
                <groupId>org.liquibase</groupId>
                <artifactId>liquibase-maven-plugin</artifactId>
                <version>3.10.2</version>
                <configuration>
                    <propertyFileWillOverride>true</propertyFileWillOverride>
                    <propertyFile>src/main/resources/liquibase.properties</propertyFile>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.jetbrains.kotlin</groupId>
                <artifactId>kotlin-maven-plugin</artifactId>
                <configuration>
                    <args>
                        <arg>-Xjsr305=strict</arg>
                    </args>
                    <compilerPlugins>
                        <plugin>spring</plugin>
                    </compilerPlugins>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.jetbrains.kotlin</groupId>
                        <artifactId>kotlin-maven-allopen</artifactId>
                        <version>${kotlin.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
</project>

4.0.0
org.springframework.boot
spring启动程序父级
2.3.3.2发布
环球
费率
0.0.1-快照
费率
费率
jcenter
https://jcenter.bintray.com/
UTF-8
UTF-8
11
2.22.2
1.3.72
org.springframework.boot
SpringBootStarterWeb
org.springframework.boot
spring引导启动器数据jpa
org.springframework.data
spring数据jpa
2.3.4.1发布
org.springframework.boot
弹簧靴起动器执行器
org.springframework.cloud
春季云启动程序
2.2.2.1发布
com.google.code.gson
格森
2.8.6
com.fasterxml.jackson.module
杰克逊模块科特林
khttp
khttp
1.0.0
org.jetbrains.kotlin
科特林反射
org.jetbrains.kotlin
kotlin-stdlib-jdk8
org.liquibase
液化酶核心
1.9.5
org.springframework.boot
弹簧起动试验
测试
org.junit.vintage
朱尼特老式发动机
org.apache.logging.log4j
log4j型芯
2.13.3
mysql
mysql连接器java
${mysql.version}
${project.basedir}/src/main/kotlin
${project.basedir}/src/test/kotlin
org.springframework.boot
springbootmaven插件
重新包装
全球运价应用
org.liquibase
liquibase maven插件
3.10.2
真的
src/main/resources/liquibase.properties
org.jetbrains.kotlin
kotlin maven插件
-Xjsr305=严格
春天
org.jetbrains.kotlin
科特林·马文·阿洛彭
${kotlin.version}

底层的Hibernate层可能会影响您在此处的保存。除非调用
commit
flush
,否则通常不会将实体写入数据库。 还有另一种方法可以立即将实体写入数据库。它被称为
saveAndFlush
。也许你应该考虑使用这个方法,如果你想立即坚持下去。< /P> 或许本文可以澄清这一区别: