Код: Выделить всё
@Entity
@Table(name = "SECTIONS")
data class Section(
@Id @GeneratedValue
@Column(name = "ID")
var id: Long = 0,
@Column(name = "NAME")
var name: String = "",
@OneToMany(
mappedBy = "section",
fetch = FetchType.EAGER,
cascade = arrayOf(CascadeType.ALL),
orphanRemoval = true
)
var fields: MutableList = mutableListOf()
)
@Entity
@Table(name = "FIELDS")
data class Field(
@Id @GeneratedValue
@Column(name = "ID")
var id: Long = 0,
@Column(name = "NAME")
var name: String = "",
@ManyToOne
@JoinColumn(name = "SECTION_ID")
var section: Section? = null
)
Код: Выделить всё
@Test
fun testCascadeSaving() {
val section = Section(name = "Section 1")
val field = Field(name = "Field 1")
section.fields.add(field)
field.section = section
val savedSection = sectionRepository.save(section)
val savedField = savedSection.fields[0]
// This causes an StackOverflowError
val f = fieldRepository.findOne(savedField.id)
}
Есть идеи, почему установка двунаправленной связи вызывает эту ошибку?
Подробнее здесь: https://stackoverflow.com/questions/471 ... -in-kotlin
Мобильная версия