【问题标题】:Spring data JPA throwing java.lang.ArrayIndexOutOfBoundsException: X [Kotlin]Spring数据JPA抛出java.lang.ArrayIndexOutOfBoundsException:X [Kotlin]
【发布时间】:2020-03-06 03:53:36
【问题描述】:

Entity 的属性之一是inline class(在提出此问题时是一个实验性功能)。在运行 Spring Boot 应用程序时,我收到了 java.lang.ArrayIndexOutOfBoundsException: 3,这对我来说毫无意义。

原来3 是表示属性在我的实体中的位置的数字。

@Entity
@Table(name = "my_entity_table")
class MyEntity(
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    var id: Long = 0,

    @Column(name = "some_field")
    val someField: Int = 2,

    @Column(name = "a_second_field")
    val aSecondField: ASecondField
)

inline class ASecondField(val value: String)

这是堆栈跟踪的一部分:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myEntityRepository': Invocation of init method failed; nested exception is java.lang.ArrayIndexOutOfBoundsException: 3


...

Caused by: java.lang.ArrayIndexOutOfBoundsException: 3
    at org.springframework.data.mapping.model.PreferredConstructorDiscoverer$Discoverers.buildPreferredConstructor(PreferredConstructorDiscoverer.java:221)
    at org.springframework.data.mapping.model.PreferredConstructorDiscoverer$Discoverers.access$200(PreferredConstructorDiscoverer.java:89)
    at org.springframework.data.mapping.model.PreferredConstructorDiscoverer$Discoverers$2.lambda$discover$0(PreferredConstructorDiscoverer.java:161)

...

【问题讨论】:

    标签: jpa kotlin spring-data-jpa


    【解决方案1】:

    解决方案是让我的内联类(示例中为ASecondField)成为typealias

    原来的代码是:

    inline class ASecondField(val value: String)
    

    我就是这样解决的:

    typealias ASecondField = String
    

    当然这不是最佳答案,因为我不得不更改原始设计。

    【讨论】:

      猜你喜欢
      • 2021-05-26
      • 1970-01-01
      • 1970-01-01
      • 2020-01-27
      • 2021-08-31
      • 1970-01-01
      • 2018-08-02
      • 1970-01-01
      • 2022-01-01
      相关资源
      最近更新 更多