Skip to content

Constructor based instantiation of entities fails due to missing converters. [DATAGRAPH-1182] #1712

@spring-projects-issues

Description

@spring-projects-issues

Michael Simons opened DATAGRAPH-1182 and commented

Given an entity like

class Person {
    Integer something;

    public Person(Integer something) {
        this.something = something;
    }
}

Instantiation of such an entity during load fails with an ConverterNotFoundException:

Caused by: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.Long] to type [java.lang.Integer]
	at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:321) ~[spring-core-5.1.4.RELEASE.jar:5.1.4.RELEASE]
	at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:194) ~[spring-core-5.1.4.RELEASE.jar:5.1.4.RELEASE]
	at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:174) ~[spring-core-5.1.4.RELEASE.jar:5.1.4.RELEASE]
	at org.springframework.data.neo4j.conversion.Neo4jOgmEntityInstantiatorAdapter$Neo4jPropertyValueProvider.getParameterValue(Neo4jOgmEntityInstantiatorAdapter.java:84) ~[spring-data-neo4j-5.1.4.RELEASE.jar:5.1.4.RELEASE]
	at org.springframework.data.convert.ClassGeneratingEntityInstantiator$EntityInstantiatorAdapter.extractInvocationArguments(ClassGeneratingEntityInstantiator.java:250) ~[spring-data-commons-2.1.4.RELEASE.jar:2.1.4.RELEASE]
	at org.springframework.data.convert.ClassGeneratingEntityInstantiator$EntityInstantiatorAdapter.createInstance(ClassGeneratingEntityInstantiator.java:223) ~[spring-data-commons-2.1.4.RELEASE.jar:2.1.4.RELEASE]
	at org.springframework.data.convert.ClassGeneratingEntityInstantiator.createInstance(ClassGeneratingEntityInstantiator.java:84) ~[spring-data-commons-2.1.4.RELEASE.jar:2.1.4.RELEASE]
	at org.springframework.data.neo4j.conversion.Neo4jOgmEntityInstantiatorAdapter.createInstance(Neo4jOgmEntityInstantiatorAdapter.java:57) ~[spring-data-neo4j-5.1.4.RELEASE.jar:5.1.4.RELEASE]
	at org.neo4j.ogm.metadata.reflect.EntityFactory.instantiate(EntityFactory.java:126) ~[neo4j-ogm-core-3.1.6.jar:3.1.6]
	at org.neo4j.ogm.metadata.reflect.EntityFactory.newObject(EntityFactory.java:95) ~[neo4j-ogm-core-3.1.6.jar:3.1.6]
	at org.neo4j.ogm.context.GraphEntityMapper.mapNodes(GraphEntityMapper.java:237) ~[neo4j-ogm-core-3.1.6.jar:3.1.6]
	at org.neo4j.ogm.context.GraphEntityMapper.mapEntities(GraphEntityMapper.java:212) ~[neo4j-ogm-core-3.1.6.jar:3.1.6]
	... 51 common frames omitted

This happens in all scenarios where no default Spring converters are defined or more than one.

The ParameterValueProvider for Neo4j's persistent properties then returns the numerical long value from the driver as is (see org.springframework.data.neo4j.conversion.Neo4jOgmEntityInstantiatorAdapter.Neo4jPropertyValueProvider).

This doesn't happen when the entity is instantiated with the default constructor and it's fields are written by OGM, as OGM forcefully coerces longs into ints


Affects: 5.2 M1 (Moore), 5.1.4 (Lovelace SR4)

Metadata

Metadata

Labels

in: coreIssues in core supporttype: bugA general bug

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions