Kotlin 1.2.20与弹簧靴1.5.9兼容

时间:2018-01-19 04:12:15

标签: hibernate spring-boot kotlin

我有一个带有kotlin 1.2.10的Spring启动项目,每当我尝试在我的pom.xml中将Kotlin版本切换到1.2.20时,我的Junit与data.sql中包含的数据有关。其他测试仍然可以。所以我猜想data.sql没有正确加载。

这是测试中的一个:

   @Test
    fun findOne() {
        val child= repository.findOne(1L)
        Assertions.assertThat(child.firstname)
                .isEqualTo("firstname")
    }

这是存储库的代码:

internal interface ChildRepository : JpaRepository<Child, Long>{

    @Query("select c from Child c where c.daycare.id=:idDaycare")
    fun findAllByDaycare(@Param("idDaycare") id: Long): MutableList<Child>

    @Query("select c from Child c where c.id=:id and c.daycare.id=:idDaycare")
    fun findOneByIdByDaycare(@Param("id") id: Long,@Param("idDaycare") idDaycare: Long): Child
}

在错误上添加堆栈:

java.lang.NullPointerException
    at com.ablx.daycare.backend.repository.ChildRepositoryTest.findOne(ChildRepositoryTest.kt:21)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

添加实体:

@Entity
internal data class Child(
        @field: Id @field: GeneratedValue var id: Long = 0, //Primary Key
        var firstname: String = "",
        var lastname: String = "",
        @ManyToOne(fetch = FetchType.EAGER)
        @JoinColumn(name = "daycare")
        var daycare: Daycare = Daycare(),
        @get:JsonIgnore
        @OneToMany(mappedBy = "child", cascade = [CascadeType.ALL], fetch = FetchType.LAZY)
        var sumups: List<Sumup> = emptyList()
)
{
        override fun toString(): String {
                return "Child(id=$id, firstname='$firstname', lastname='$lastname', daycare=$daycare)"
        }
}

春天回购并没有找到我的实体,只要我切换回1.2.10。测试没问题。

当我切换到Kotlin 1.2.20时,我应该修改一些东西吗?

在我的pom.xml中将kotlin.compiler.incremental转为false使得kotlin 1.2.20上的构建正常。不明白为什么。

切换回Kotlin 1.2.10现在解决了我的问题。

0 个答案:

没有答案