Skip to content

Fix NullPointerException when using known entities inside projections. #2349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pelletier197 opened this issue Aug 5, 2021 · 4 comments
Closed
Assignees
Labels
type: bug A general bug

Comments

@pelletier197
Copy link

pelletier197 commented Aug 5, 2021

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!

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 5, 2021
@michael-simons
Copy link
Collaborator

michael-simons commented Aug 5, 2021

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

I see no such field in the class you shared.

Can you please share a small reproducer, including a dataset? Thanks.

@michael-simons michael-simons self-assigned this Aug 5, 2021
@pelletier197
Copy link
Author

There is no field in the person entity. This is wished for us for performance purpose. I showed something really simplified compared to our use case, but we can't put the field in the entity. The code I shared will produce the NPE.

@michael-simons
Copy link
Collaborator

michael-simons commented Aug 9, 2021

The code you shared is incomplete and has errors, however I try to investigate nevertheless.

@michael-simons michael-simons added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 9, 2021
@michael-simons michael-simons changed the title NPE in projection with another object Fix NullPointerException when using known entities inside projections. Aug 9, 2021
@michael-simons michael-simons added this to the 6.1.4 (2021.0.4) milestone Aug 9, 2021
@michael-simons
Copy link
Collaborator

Reproduced and fixed. Will be available in the next 6.1 patch release. Thank you very much for your report.

michael-simons added a commit that referenced this issue Aug 9, 2021
… projections.

When a known entity is discovered in the PropertyFilterSupport, it can be used directly as the property type than is equal to a domain type (a well known entity).

Prior to that change, the discovered well known entity was used and it was asked for the the type of the property of the containing class again, which is wrong in most cases that don't have a property of the fitting type _and_ the same name again.

In addition, one other bug has been fixed: The `Neo4jTemplate` did not pass result type and domain type in the `saveAs` method to the `PropertyFilterSupport`, but only the result type, leading to the original fix to blow up.
Having fixed that bug, it became appearent that in the `PropertyFilterSupport` the overloads of `addPropertiesFrom` different order of `domainType` and `returnType`which then has been fixed as well.

This closes #2349.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants