Skip to content

In Kotlin, specifying a default entity graph make query fail with Stackoverflow exception #119

Open
@mr-nothing

Description

@mr-nothing

For some reason specifying DynamicEntityGraph as a default one make repository.findById(id: String) fail with stackoverflow exception. Was unable to understand if it is a bug or I just misuse/misconfigured something.

Steps to reproduce the behaviour:

  1. Define repository as follows:
@Repository
interface MyEntityRepository : EntityGraphJpaRepository<MyEntity, String> {
    override fun defaultEntityGraph(): Optional<EntityGraph> {
        return Optional.of(
            DynamicEntityGraph.loading(listOf("field1", "field2", "field3", "field4"))
        )
    }
// Here goes some custom methods
}

Where fieldN is a OneToOne relation fields.

  1. Call findById repository method as follows:
class MyService(
    private val myEntityRepository: MyEntityRepository
) {
fun getMyEntityById(entityId: String): MyEntity {
    return myRepository.findById(entityId).orElseThrow {
        NotFoundException("Entity not found")
    }
}
  1. Make this method be called by any of your rest endpoints.

What is the expected output ?

DynamicEntityGraph should be used to fetch MyEntity data.

What happens instead ?

Query fails with stackoverflow error.
error.log

Environment

  • Spring Data JPA version: 3.1.0
  • Hibernate (hibernate-core-6.2.2.Final, hibernate-commons-annotations-6.0.6.Final, hibernate-validator-8.0.0.Final.jar)
  • spring-data-jpa-entity-graph version: 3.0.1

Link to an automated test demonstrating the problem

Unfortunately I was unable to reproduce this on sample project and I can't share my project. Will try to investigate this further but maybe stacktrace can be of some help to understand what is going on.

Additional context

n/a

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions