Skip to content

Fix NullPointerException when using known entities inside projections. #2349

@pelletier197

Description

@pelletier197

I'm experiencing some issues with the latest version 6.1.3 with the mapping that has changed. The following does not work anymore:

@Node("Person")
data class PersonEntity(
    @Id
    val id: String,
    val email: String,
)

@Node("Department")
data class DepartmentEntity(
    @Id
    val id: String,
    val name: String
)


data class PersonDepartmentQueryResult(
    val person: PersonEntity,
    val department: DepartmentEntity,
)

interface PersonRepository : Neo4jRepository<PersonEntity, String> {
    @Query(
        """
        MATCH (person:Person)-[:MEMBER_OF]->(department:Department)
        RETURN person, department
    """
    )
    fun findPersonWithDepartment(): List<PersonQueryResult>
}

@Service
class TestService(
    personRepo: PersonRepository,
) {
    init {
            println(personRepo.findPersonWithDepartment())
    }
}

which produces the following stacktrace :

Caused by: java.lang.NullPointerException: null
	at org.springframework.data.neo4j.core.PropertyFilterSupport.processEntity(PropertyFilterSupport.java:125)
	at org.springframework.data.neo4j.core.PropertyFilterSupport.addPropertiesFrom(PropertyFilterSupport.java:100)
	at org.springframework.data.neo4j.core.PropertyFilterSupport.getInputProperties(PropertyFilterSupport.java:54)
	at org.springframework.data.neo4j.repository.query.AbstractNeo4jQuery.execute(AbstractNeo4jQuery.java:90)
	at org.springframework.data.repository.core.support.RepositoryMethodInvoker.doInvoke(RepositoryMethodInvoker.java:137)
	at org.springframework.data.repository.core.support.RepositoryMethodInvoker.invoke(RepositoryMethodInvoker.java:121)

It tries to fetch the department field in the person entity, and PropertyFilterSupport doesn't handle the null persistentProperty.

I'm pretty sure this bug was introduced with the multi-level projection support: #2314

This exact query works in 6.1.2, so my expectations for the behaviour would be that this keeps working with 6.1.3.

Thank you!

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions