[DATAGRAPH-1182] Constructor based instantiation of entities fails due to missing converters. Created: 16/Jan/19  Updated: 16/Jan/19

Status: Open
Project: Spring Data Neo4j
Component/s: CORE
Affects Version/s: 5.2 M1 (Moore), 5.1.4 (Lovelace SR4)
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: Michael Simons Assignee: Michael Simons
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Last updater: Michael Simons

 Description   

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.


Generated at Sat Jan 25 16:49:53 UTC 2020 using Jira 7.13.8#713008-sha1:1606a5c1e7006e1ab135aac81f7a9566b2dbc3a6.