Spring数据JPA抛出java.lang.ArrayIndexOutOfBoundsException:X [Kotlin] [英] Spring data JPA throwing java.lang.ArrayIndexOutOfBoundsException: X [Kotlin]

查看:1815
本文介绍了Spring数据JPA抛出java.lang.ArrayIndexOutOfBoundsException:X [Kotlin]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Entity的属性之一是inline class(在提出此问题时为实验性功能).而且,当运行spring boot应用程序时,我得到的java.lang.ArrayIndexOutOfBoundsException: 3对我来说没有任何意义.

One of the attributes of an Entity was an inline class (an experimental feature at the time of this question). And when running a spring boot application I was getting a java.lang.ArrayIndexOutOfBoundsException: 3 which made no sense to me.

结果是3是表示属性在我的实体中位置的数字.

Turns out 3 was the number indicating the position of the attribute in my entity.

@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)

这是堆栈跟踪的一部分:

And this was part of the stacktrace:

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)

...

推荐答案

解决方案是将我的内联类(在示例中为ASecondField)设置为typealias.

The solution for that was to make my inline class (ASecondField in the example) a typealias.

原来的代码是:

inline class ASecondField(val value: String)

这就是我的解决方法:

typealias ASecondField = String

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

Of course this is not the optimal answer since I had to change the original design.

这篇关于Spring数据JPA抛出java.lang.ArrayIndexOutOfBoundsException:X [Kotlin]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆