Uploaded image for project: 'Spring Data Neo4j'
  1. Spring Data Neo4j
  2. DATAGRAPH-1182

Constructor based instantiation of entities fails due to missing converters.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 5.2 M1 (Moore), 5.1.4 (Lovelace SR4)
    • Fix Version/s: None
    • Component/s: CORE
    • Labels:
      None

      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.

        Attachments

          Activity

            People

            Assignee:
            michael.simons Michael Simons
            Reporter:
            michael.simons Michael Simons
            Last updater:
            Michael Simons
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: