In my @RelationshipEntity
I have defined the following dynamic properties:
@Properties(prefix = "property", allowCast = true)
private Map<Long, Object> properties;
Under the different Long
keys I need to store Map<String, Object>
object.
Everything works fine in case I store only the one Map<String, Object>
object under the one Long
key, for example on Neo4j level the following code:
Map<String, Object> valueProperties1 = new HashMap<>();
valueProperties1.put("active", true);
valueProperties1.put("selfEvaluation", 5);
valueProperties1.put("experience", "practical");
properties.put(1L, valueProperties1);
translates to the following Neo4j properties:
{
"property.1.active": true,
"property.1.selfEvaluation": 3,
"property.1.experience": "practical"
}
So far everything works fine.
But when I try to select this relationship entity, for example by the following Spring Data Neo4j repository method:
@Query("MATCH (d:Decision)-[drc:HAS_VALUE_ON]->(ch:Characteristic) WHERE d.id = {decisionId} AND ch.id = {characteristicId} RETURN d, ch, drc")
RelationshipValue findByDecisionOnCharacteristic(@Param("decisionId") Long decisionId, @Param("characteristicId") Long characteristicId);
it fails with the following exception:
org.springframework.dao.InvalidDataAccessApiUsageException: Error mapping GraphModel to instance of com.decisionwanted.domain.model.neo4j.decision.characteristic.value.RelationshipValue; nested exception is org.neo4j.ogm.exception.core.MappingException: Error mapping GraphModel to instance of com.decisionwanted.domain.model.neo4j.decision.characteristic.value.RelationshipValue
at org.springframework.data.neo4j.transaction.SessionFactoryUtils.convertOgmAccessException(SessionFactoryUtils.java:126)
at org.springframework.data.neo4j.repository.support.SessionBeanDefinitionRegistrarPostProcessor.translateExceptionIfPossible(SessionBeanDefinitionRegistrarPostProcessor.java:71)
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:61)
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:242)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:153)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
at com.sun.proxy.$Proxy156.findByDecisionOnCharacteristic(Unknown Source)
at com.decisionwanted.domain.dao.decision.characteristic.value.RelationshipValueDaoImpl.findByDecisionOnCharacteristic(RelationshipValueDaoImpl.java:175)
at com.decisionwanted.domain.dao.decision.characteristic.value.RelationshipValueDaoImpl.create(RelationshipValueDaoImpl.java:41)
at com.decisionwanted.domain.dao.decision.characteristic.value.RelationshipValueDaoImpl$$FastClassBySpringCGLIB$$5a98b507.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:747)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.validation.beanvalidation.MethodValidationInterceptor.invoke(MethodValidationInterceptor.java:112)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689)
at com.decisionwanted.domain.dao.decision.characteristic.value.RelationshipValueDaoImpl$$EnhancerBySpringCGLIB$$7cb25ddb.create(<generated>)
at com.decisionwanted.domain.dao.decision.characteristic.value.ValueDaoImpl.create(ValueDaoImpl.java:119)
at com.decisionwanted.domain.dao.decision.characteristic.value.ValueDaoImpl.create(ValueDaoImpl.java:60)
at com.decisionwanted.domain.dao.decision.characteristic.value.ValueDaoImpl$$FastClassBySpringCGLIB$$db4e63af.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:747)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.validation.beanvalidation.MethodValidationInterceptor.invoke(MethodValidationInterceptor.java:112)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689)
at com.decisionwanted.domain.dao.decision.characteristic.value.ValueDaoImpl$$EnhancerBySpringCGLIB$$2ce1d2d3.create(<generated>)
at com.decisionwanted.domain.DecisionCharacteristicIT.testMultivaluedCharacteristicValue(DecisionCharacteristicIT.java:313)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:73)
at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:83)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: org.neo4j.ogm.exception.core.MappingException: Error mapping GraphModel to instance of com.decisionwanted.domain.model.neo4j.decision.characteristic.value.RelationshipValue
at org.neo4j.ogm.context.GraphEntityMapper.mapEntities(GraphEntityMapper.java:205)
at org.neo4j.ogm.context.GraphEntityMapper.map(GraphEntityMapper.java:132)
at org.neo4j.ogm.context.GraphEntityMapper.map(GraphEntityMapper.java:88)
at org.neo4j.ogm.session.delegates.ExecuteQueriesDelegate.lambda$executeAndMap$1(ExecuteQueriesDelegate.java:124)
at org.neo4j.ogm.session.Neo4jSession.doInTransaction(Neo4jSession.java:539)
at org.neo4j.ogm.session.Neo4jSession.doInTransaction(Neo4jSession.java:523)
at org.neo4j.ogm.session.delegates.ExecuteQueriesDelegate.executeAndMap(ExecuteQueriesDelegate.java:120)
at org.neo4j.ogm.session.delegates.ExecuteQueriesDelegate.query(ExecuteQueriesDelegate.java:90)
at org.neo4j.ogm.session.Neo4jSession.query(Neo4jSession.java:414)
at sun.reflect.GeneratedMethodAccessor62.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.data.neo4j.transaction.SharedSessionCreator$SharedSessionInvocationHandler.invoke(SharedSessionCreator.java:131)
at com.sun.proxy.$Proxy112.query(Unknown Source)
at org.springframework.data.neo4j.repository.query.GraphQueryExecution$SingleEntityExecution.execute(GraphQueryExecution.java:74)
at org.springframework.data.neo4j.repository.query.GraphRepositoryQuery.doExecute(GraphRepositoryQuery.java:77)
at org.springframework.data.neo4j.repository.query.AbstractGraphRepositoryQuery.execute(AbstractGraphRepositoryQuery.java:51)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:590)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:578)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)
... 66 more
Caused by: java.lang.UnsupportedOperationException: Only String and Enum allowed to be keys, got class java.lang.Long
at org.neo4j.ogm.typeconversion.MapCompositeConverter.keyInstanceFromString(MapCompositeConverter.java:190)
at org.neo4j.ogm.typeconversion.MapCompositeConverter.putToMap(MapCompositeConverter.java:143)
at org.neo4j.ogm.typeconversion.MapCompositeConverter.toEntityAttribute(MapCompositeConverter.java:133)
at org.neo4j.ogm.typeconversion.MapCompositeConverter.toEntityAttribute(MapCompositeConverter.java:40)
at org.neo4j.ogm.context.GraphEntityMapper.getCompositeProperties(GraphEntityMapper.java:252)
at org.neo4j.ogm.context.GraphEntityMapper.createRelationshipEntity(GraphEntityMapper.java:393)
at org.neo4j.ogm.context.GraphEntityMapper.mapRelationshipEntity(GraphEntityMapper.java:351)
at org.neo4j.ogm.context.GraphEntityMapper.mapRelationships(GraphEntityMapper.java:325)
at org.neo4j.ogm.context.GraphEntityMapper.mapEntities(GraphEntityMapper.java:201)
... 91 more
What am I doing wrong and how to fix it ?
The documentation mentions
Supported types for keys in the Map are String and Enum.
This is the same message that can be found in your logs:
Caused by: java.lang.UnsupportedOperationException: Supported types for keys in the Map are String and Enum.
Still I am not sure why it is working in the first place. Is it possible that you did not load the entity back when saving it in the first case? I do get the error even with a single long keyed entry.