Hi, i'm trying to create a relationship between two different classes; Resource, and ResourceService. When I create the relationship I can see the start and end nodes are correct but the id is null.. my test has two repositories configured
// throws not found exception in test method Resource res = template.save( new Resource("123", "resourceTest") ); ResourceService rservice = template.save( new ResourceService("101", "resourceService", "me", "http://example.com") ); ConsumesResource cr = rservice.addConsumedResource(res); template.save( cr ); // start and end nodes are correct but id is null - throws exception
Here is the stack trace org.neo4j.graphdb.NotFoundException: '__type__' property not found for RelationshipImpl #11 of type 2 between Node[12] and Node[15]. at org.neo4j.kernel.impl.core.Primitive.newPropertyNotFoundException(Primitive .java:183) at org.neo4j.kernel.impl.core.Primitive.getProperty(Primitive.java:178) at org.neo4j.kernel.impl.core.RelationshipProxy.getProperty(RelationshipProxy. java:90) at org.springframework.data.neo4j.support.typerepresentation.AbstractIndexingT ypeRepresentationStrategy.getJavaType(AbstractIndexingTypeRepresentationStr ategy.java:89) at org.springframework.data.neo4j.support.mapping.TRSTypeAliasAccessor.readAli asFrom(TRSTypeAliasAccessor.java:39) at org.springframework.data.neo4j.support.mapping.TRSTypeAliasAccessor.readAli asFrom(TRSTypeAliasAccessor.java:29) at org.springframework.data.convert.DefaultTypeMapper.readType(DefaultTypeMapp er.java:72) at org.springframework.data.convert.DefaultTypeMapper.getDefaultedTypeToBeUsed (DefaultTypeMapper.java:116) at org.springframework.data.convert.DefaultTypeMapper.readType(DefaultTypeMapp er.java:93) at org.springframework.data.neo4j.support.mapping.Neo4jEntityConverterImpl.rea d(Neo4jEntityConverterImpl.java:74) at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister$CachedC onverter.read(Neo4jEntityPersister.java:168) at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister.createE ntityFromState(Neo4jEntityPersister.java:189) at org.springframework.data.neo4j.support.Neo4jTemplate.createEntityFromState( Neo4jTemplate.java:190) at org.springframework.data.neo4j.fieldaccess.GraphBackedEntityIterableWrapper .underlyingObjectToObject(GraphBackedEntityIterableWrapper.java:38) at org.springframework.data.neo4j.fieldaccess.GraphBackedEntityIterableWrapper .underlyingObjectToObject(GraphBackedEntityIterableWrapper.java:26) at org.neo4j.helpers.collection.IterableWrapper$MyIteratorWrapper.underlyingOb jectToObject(IterableWrapper.java:57) at org.neo4j.helpers.collection.IteratorWrapper.next(IteratorWrapper.java:47) at org.neo4j.helpers.collection.IteratorUtil.addToCollection(IteratorUtil.java :322) at org.neo4j.helpers.collection.IteratorUtil.addToCollection(IteratorUtil.java :339) at org.springframework.data.neo4j.fieldaccess.OneToNRelationshipEntityFieldAcc essorFactory$OneToNRelationshipEntityFieldAccessor.getValue(OneToNRelations hipEntityFieldAccessorFactory.java:119) at org.springframework.data.neo4j.fieldaccess.DefaultEntityState.getValue(Defa ultEntityState.java:97) at org.springframework.data.neo4j.support.mapping.SourceStateTransmitter.copyE ntityStatePropertyValue(SourceStateTransmitter.java:110) at org.springframework.data.neo4j.support.mapping.SourceStateTransmitter.acces s$000(SourceStateTransmitter.java:39) at org.springframework.data.neo4j.support.mapping.SourceStateTransmitter$2.doW ithAssociation(SourceStateTransmitter.java:64) at org.springframework.data.mapping.model.BasicPersistentEntity.doWithAssociat ions(BasicPersistentEntity.java:185) at org.springframework.data.neo4j.support.mapping.SourceStateTransmitter.copyP ropertiesFrom(SourceStateTransmitter.java:60) at org.springframework.data.neo4j.support.mapping.Neo4jEntityConverterImpl.loa dEntity(Neo4jEntityConverterImpl.java:98) at org.springframework.data.neo4j.support.mapping.Neo4jEntityConverterImpl.rea d(Neo4jEntityConverterImpl.java:90) at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister$CachedC onverter.read(Neo4jEntityPersister.java:168) at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister.createE ntityFromState(Neo4jEntityPersister.java:186) at org.springframework.data.neo4j.support.Neo4jTemplate.createEntityFromState( Neo4jTemplate.java:190) at org.springframework.data.neo4j.fieldaccess.RelationshipNodeFieldAccessorFac tory$RelationshipNodeFieldAccessor.getValue(RelationshipNodeFieldAccessorFa ctory.java:102) at org.springframework.data.neo4j.fieldaccess.DefaultEntityState.getValue(Defa ultEntityState.java:97) at org.springframework.data.neo4j.support.mapping.SourceStateTransmitter.copyE ntityStatePropertyValue(SourceStateTransmitter.java:110) at org.springframework.data.neo4j.support.mapping.SourceStateTransmitter.acces s$000(SourceStateTransmitter.java:39) at org.springframework.data.neo4j.support.mapping.SourceStateTransmitter$2.doW ithAssociation(SourceStateTransmitter.java:64) at org.springframework.data.mapping.model.BasicPersistentEntity.doWithAssociat ions(BasicPersistentEntity.java:185) at org.springframework.data.neo4j.support.mapping.SourceStateTransmitter.copyP ropertiesFrom(SourceStateTransmitter.java:60) at org.springframework.data.neo4j.support.mapping.Neo4jEntityConverterImpl.loa dEntity(Neo4jEntityConverterImpl.java:98) at org.springframework.data.neo4j.support.mapping.Neo4jEntityConverterImpl.rea d(Neo4jEntityConverterImpl.java:90) at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister$CachedC onverter.read(Neo4jEntityPersister.java:168) at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister.createE ntityFromState(Neo4jEntityPersister.java:189) at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister.persist (Neo4jEntityPersister.java:245) at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister.persist (Neo4jEntityPersister.java:227) at org.springframework.data.neo4j.support.Neo4jTemplate.save(Neo4jTemplate.jav a:295) at jackal.mytest.domain.DomainTest.resourcesCanBeConsumed(DomainTest.java:156) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:5 7) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImp l.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod .java:44) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable. java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.j ava:41) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.ja va:20) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:2 8) at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallb acks.evaluate(RunBeforeTestMethodCallbacks.java:74) at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallba cks.evaluate(RunAfterTestMethodCallbacks.java:82) at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(Sp ringRepeat.java:72) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(Sp ringJUnit4ClassRunner.java:231) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.ja va:49) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallba cks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbac ks.evaluate(RunAfterTestClassCallbacks.java:70) at org.junit.runners.ParentRunner.run(ParentRunner.java:236) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJ Unit4ClassRunner.java:174) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestRe ference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java: 38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestR unner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestR unner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner .java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunne r.java:197)
my classes - Service has @NodeEntity public class ResourceService extends Service { public ResourceService(String id, String name, String owner, String uri) { super(id, name, owner, uri); }
The problem is that you have the same relationship twice in your class,
once with the @RelatedToVia and once with @RelatedTo
now you add it to both collections and save the entity.
the collection consumesResource is saved first, creating neo4j relationships without any corresponding type information,
then it tries to save consumesRelationships and in between tries to determine existing relationships of this rel-type and fails b/c the existing relationships have not (as expected any java type (in this case ConsumesResource) connected).
if you don't store additional properties on ConsumesResource you don't need it
and then you also don't need the @RelatedToVia collection
in any other case it would be sensible only to fill consumesRelationships when adding Resources, and keeping consumesResource to null which is then ignored.
> Hi, i'm trying to create a relationship between two different classes; Resource, and ResourceService. When I create the relationship I can see the start and end nodes are correct but the id is null.. my test has two repositories configured
> // throws not found exception in test method
> Resource res = template.save( new Resource("123", "resourceTest") );
> ResourceService rservice = template.save( new ResourceService("101", "resourceService", "me", "http://example.com") );
> ConsumesResource cr = rservice.addConsumedResource(res);
> template.save( cr ); // start and end nodes are correct but id is null - throws exception
> Here is the stack trace
> org.neo4j.graphdb.NotFoundException: '__type__' property not found for RelationshipImpl #11 of type 2 between Node[12] and Node[15].
> at org.neo4j.kernel.impl.core.Primitive.newPropertyNotFoundException(Primitive .java:183)
> at org.neo4j.kernel.impl.core.Primitive.getProperty(Primitive.java:178)
> at org.neo4j.kernel.impl.core.RelationshipProxy.getProperty(RelationshipProxy. java:90)
> at org.springframework.data.neo4j.support.typerepresentation.AbstractIndexingT ypeRepresentationStrategy.getJavaType(AbstractIndexingTypeRepresentationStr ategy.java:89)
> at org.springframework.data.neo4j.support.mapping.TRSTypeAliasAccessor.readAli asFrom(TRSTypeAliasAccessor.java:39)
> at org.springframework.data.neo4j.support.mapping.TRSTypeAliasAccessor.readAli asFrom(TRSTypeAliasAccessor.java:29)
> at org.springframework.data.convert.DefaultTypeMapper.readType(DefaultTypeMapp er.java:72)
> at org.springframework.data.convert.DefaultTypeMapper.getDefaultedTypeToBeUsed (DefaultTypeMapper.java:116)
> at org.springframework.data.convert.DefaultTypeMapper.readType(DefaultTypeMapp er.java:93)
> at org.springframework.data.neo4j.support.mapping.Neo4jEntityConverterImpl.rea d(Neo4jEntityConverterImpl.java:74)
> at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister$CachedC onverter.read(Neo4jEntityPersister.java:168)
> at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister.createE ntityFromState(Neo4jEntityPersister.java:189)
> at org.springframework.data.neo4j.support.Neo4jTemplate.createEntityFromState( Neo4jTemplate.java:190)
> at org.springframework.data.neo4j.fieldaccess.GraphBackedEntityIterableWrapper .underlyingObjectToObject(GraphBackedEntityIterableWrapper.java:38)
> at org.springframework.data.neo4j.fieldaccess.GraphBackedEntityIterableWrapper .underlyingObjectToObject(GraphBackedEntityIterableWrapper.java:26)
> at org.neo4j.helpers.collection.IterableWrapper$MyIteratorWrapper.underlyingOb jectToObject(IterableWrapper.java:57)
> at org.neo4j.helpers.collection.IteratorWrapper.next(IteratorWrapper.java:47)
> at org.neo4j.helpers.collection.IteratorUtil.addToCollection(IteratorUtil.java :322)
> at org.neo4j.helpers.collection.IteratorUtil.addToCollection(IteratorUtil.java :339)
> at org.springframework.data.neo4j.fieldaccess.OneToNRelationshipEntityFieldAcc essorFactory$OneToNRelationshipEntityFieldAccessor.getValue(OneToNRelations hipEntityFieldAccessorFactory.java:119)
> at org.springframework.data.neo4j.fieldaccess.DefaultEntityState.getValue(Defa ultEntityState.java:97)
> at org.springframework.data.neo4j.support.mapping.SourceStateTransmitter.copyE ntityStatePropertyValue(SourceStateTransmitter.java:110)
> at org.springframework.data.neo4j.support.mapping.SourceStateTransmitter.acces s$000(SourceStateTransmitter.java:39)
> at org.springframework.data.neo4j.support.mapping.SourceStateTransmitter$2.doW ithAssociation(SourceStateTransmitter.java:64)
> at org.springframework.data.mapping.model.BasicPersistentEntity.doWithAssociat ions(BasicPersistentEntity.java:185)
> at org.springframework.data.neo4j.support.mapping.SourceStateTransmitter.copyP ropertiesFrom(SourceStateTransmitter.java:60)
> at org.springframework.data.neo4j.support.mapping.Neo4jEntityConverterImpl.loa dEntity(Neo4jEntityConverterImpl.java:98)
> at org.springframework.data.neo4j.support.mapping.Neo4jEntityConverterImpl.rea d(Neo4jEntityConverterImpl.java:90)
> at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister$CachedC onverter.read(Neo4jEntityPersister.java:168)
> at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister.createE ntityFromState(Neo4jEntityPersister.java:186)
> at org.springframework.data.neo4j.support.Neo4jTemplate.createEntityFromState( Neo4jTemplate.java:190)
> at org.springframework.data.neo4j.fieldaccess.RelationshipNodeFieldAccessorFac tory$RelationshipNodeFieldAccessor.getValue(RelationshipNodeFieldAccessorFa ctory.java:102)
> at org.springframework.data.neo4j.fieldaccess.DefaultEntityState.getValue(Defa ultEntityState.java:97)
> at org.springframework.data.neo4j.support.mapping.SourceStateTransmitter.copyE ntityStatePropertyValue(SourceStateTransmitter.java:110)
> at org.springframework.data.neo4j.support.mapping.SourceStateTransmitter.acces s$000(SourceStateTransmitter.java:39)
> at org.springframework.data.neo4j.support.mapping.SourceStateTransmitter$2.doW ithAssociation(SourceStateTransmitter.java:64)
> at org.springframework.data.mapping.model.BasicPersistentEntity.doWithAssociat ions(BasicPersistentEntity.java:185)
> at org.springframework.data.neo4j.support.mapping.SourceStateTransmitter.copyP ropertiesFrom(SourceStateTransmitter.java:60)
> at org.springframework.data.neo4j.support.mapping.Neo4jEntityConverterImpl.loa dEntity(Neo4jEntityConverterImpl.java:98)
> at org.springframework.data.neo4j.support.mapping.Neo4jEntityConverterImpl.rea d(Neo4jEntityConverterImpl.java:90)
> at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister$CachedC onverter.read(Neo4jEntityPersister.java:168)
> at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister.createE ntityFromState(Neo4jEntityPersister.java:189)
> at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister.persist (Neo4jEntityPersister.java:245)
> at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister.persist (Neo4jEntityPersister.java:227)
> at org.springframework.data.neo4j.support.Neo4jTemplate.save(Neo4jTemplate.jav a:295)
> at jackal.mytest.domain.DomainTest.resourcesCanBeConsumed(DomainTest.java:156)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:5 7)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImp l.java:43)
> at java.lang.reflect.Method.invoke(Method.java:601)
> at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod .java:44)
> at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable. java:15)
> at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.j ava:41)
> at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.ja va:20)
> at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:2 8)
> at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallb acks.evaluate(RunBeforeTestMethodCallbacks.java:74)
> at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallba cks.evaluate(RunAfterTestMethodCallbacks.java:82)
> at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(Sp ringRepeat.java:72)
> at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(Sp ringJUnit4ClassRunner.java:231)
> at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.ja va:49)
> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
> at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
> at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
> at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallba cks.evaluate(RunBeforeTestClassCallbacks.java:61)
> at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbac ks.evaluate(RunAfterTestClassCallbacks.java:70)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
> at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJ Unit4ClassRunner.java:174)
> at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestRe ference.java:50)
> at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java: 38)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestR unner.java:467)
> at
Thanks that fixed one of my problems. I haven't put any other properties in ConsumesResource because I was trying to start simple, I could add some properties but would like this to be working first. So I also have a relationship entity ResourceRelationship which is working after your advice, but when I try connecting a Resource to ResourceService I still have problems. The relationship entity ConsumesResource has an ID and appears to be saved. // from class ResourceService public ConsumesResource addConsumedResource(Resource res) { final ConsumesResource cr = new ConsumesResource(this, res); this.consumesRelationships.add(cr); return cr; } //// // test method Resource res = template.save( new Resource("123", "resourceTest") ); ResourceService rservice = template.save( new ResourceService("101", "resourceService", "me", "http://example.com") ); Resource rez = template.save( new resource("124", "resourceTest2") );
ResourceService test = this.serviceRepository.findByName(rservice.getName()); // this is null..? i also tried "resourceService" Iterator<ResourceService> rTest = this.serviceRepository.findAll().iterator(); // this works... while(rTest.hasNext()) { test = rTest.next(); System.out.println("Service repository service: " + test.toString()); // prints out resourceService... System.out.println("Any Relationships? " + test.getConsumedResources().iterator().next().toString()); // this prints out relationship... }
In this same test method I tried getting the resource from resourceRepository just to see what it would return
Resource temp = this.resourceRepository.findByName("resourceTest"); // gives me the resource
Could this have to do with ResourceService extending service (has name field)? I'm not sure what's going on..
On Sunday, April 29, 2012 8:53:44 PM UTC-4, Michael Hunger wrote:
> The problem is that you have the same relationship twice in your class,
> once with the @RelatedToVia and once with @RelatedTo
> now you add it to both collections and save the entity.
> the collection consumesResource is saved first, creating neo4j > relationships without any corresponding type information,
> then it tries to save consumesRelationships and in between tries to > determine existing relationships of this rel-type and fails b/c the > existing relationships have not (as expected any java type (in this case > ConsumesResource) connected).
> if you don't store additional properties on ConsumesResource you don't > need it
> and then you also don't need the @RelatedToVia collection
> in any other case it would be sensible only to fill consumesRelationships > when adding Resources, and keeping consumesResource to null which is then > ignored.
> HTH
> Michael
> Am 30.04.2012 um 02:34 schrieb Chris:
> > Hi, i'm trying to create a relationship between two different classes; > Resource, and ResourceService. When I create the relationship I can see the > start and end nodes are correct but the id is null.. my test has two > repositories configured
> > // throws not found exception in test method > > Resource res = template.save( new Resource("123", "resourceTest") ); > > ResourceService rservice = template.save( new ResourceService("101", > "resourceService", "me", "http://example.com") ); > > ConsumesResource cr = rservice.addConsumedResource(res); > > template.save( cr ); // start and end nodes are correct but id is null - > throws exception
> > Here is the stack trace > > org.neo4j.graphdb.NotFoundException: '__type__' property not found for > RelationshipImpl #11 of type 2 between Node[12] and Node[15]. > > at > org.neo4j.kernel.impl.core.Primitive.newPropertyNotFoundException(Primitive .java:183)
> > at > org.neo4j.kernel.impl.core.Primitive.getProperty(Primitive.java:178) > > at > org.neo4j.kernel.impl.core.RelationshipProxy.getProperty(RelationshipProxy. java:90)
> > at > org.springframework.data.neo4j.support.typerepresentation.AbstractIndexingT ypeRepresentationStrategy.getJavaType(AbstractIndexingTypeRepresentationStr ategy.java:89)
> > at > org.springframework.data.neo4j.support.mapping.TRSTypeAliasAccessor.readAli asFrom(TRSTypeAliasAccessor.java:39)
> > at > org.springframework.data.neo4j.support.mapping.TRSTypeAliasAccessor.readAli asFrom(TRSTypeAliasAccessor.java:29)
> > at > org.springframework.data.convert.DefaultTypeMapper.readType(DefaultTypeMapp er.java:72)
> > at > org.springframework.data.convert.DefaultTypeMapper.getDefaultedTypeToBeUsed (DefaultTypeMapper.java:116)
> > at > org.springframework.data.convert.DefaultTypeMapper.readType(DefaultTypeMapp er.java:93)
> > at > org.springframework.data.neo4j.support.mapping.Neo4jEntityConverterImpl.rea d(Neo4jEntityConverterImpl.java:74)
> > at > org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister$CachedC onverter.read(Neo4jEntityPersister.java:168)
> > at > org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister.createE ntityFromState(Neo4jEntityPersister.java:189)
> > at > org.springframework.data.neo4j.support.Neo4jTemplate.createEntityFromState( Neo4jTemplate.java:190)
> > at > org.springframework.data.neo4j.fieldaccess.GraphBackedEntityIterableWrapper .underlyingObjectToObject(GraphBackedEntityIterableWrapper.java:38)
> > at > org.springframework.data.neo4j.fieldaccess.GraphBackedEntityIterableWrapper .underlyingObjectToObject(GraphBackedEntityIterableWrapper.java:26)
> > at > org.neo4j.helpers.collection.IterableWrapper$MyIteratorWrapper.underlyingOb jectToObject(IterableWrapper.java:57)
> > at > org.neo4j.helpers.collection.IteratorWrapper.next(IteratorWrapper.java:47) > > at > org.neo4j.helpers.collection.IteratorUtil.addToCollection(IteratorUtil.java :322)
> > at > org.neo4j.helpers.collection.IteratorUtil.addToCollection(IteratorUtil.java :339)
> > at > org.springframework.data.neo4j.fieldaccess.OneToNRelationshipEntityFieldAcc essorFactory$OneToNRelationshipEntityFieldAccessor.getValue(OneToNRelations hipEntityFieldAccessorFactory.java:119)
> > at > org.springframework.data.neo4j.fieldaccess.DefaultEntityState.getValue(Defa ultEntityState.java:97)
> > at > org.springframework.data.neo4j.support.mapping.SourceStateTransmitter.copyE ntityStatePropertyValue(SourceStateTransmitter.java:110)
> > at > org.springframework.data.neo4j.support.mapping.SourceStateTransmitter.acces s$000(SourceStateTransmitter.java:39)
> > at > org.springframework.data.neo4j.support.mapping.SourceStateTransmitter$2.doW ithAssociation(SourceStateTransmitter.java:64)
> > at > org.springframework.data.mapping.model.BasicPersistentEntity.doWithAssociat ions(BasicPersistentEntity.java:185)
> > at > org.springframework.data.neo4j.support.mapping.SourceStateTransmitter.copyP ropertiesFrom(SourceStateTransmitter.java:60)
> > at > org.springframework.data.neo4j.support.mapping.Neo4jEntityConverterImpl.loa dEntity(Neo4jEntityConverterImpl.java:98)
> > at > org.springframework.data.neo4j.support.mapping.Neo4jEntityConverterImpl.rea d(Neo4jEntityConverterImpl.java:90)
> > at > org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister$CachedC onverter.read(Neo4jEntityPersister.java:168)
> > at > org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister.createE ntityFromState(Neo4jEntityPersister.java:186)
> > at > org.springframework.data.neo4j.support.Neo4jTemplate.createEntityFromState( Neo4jTemplate.java:190)
> > at > org.springframework.data.neo4j.fieldaccess.RelationshipNodeFieldAccessorFac tory$RelationshipNodeFieldAccessor.getValue(RelationshipNodeFieldAccessorFa ctory.java:102)
> > at > org.springframework.data.neo4j.fieldaccess.DefaultEntityState.getValue(Defa ultEntityState.java:97)
> > at > org.springframework.data.neo4j.support.mapping.SourceStateTransmitter.copyE ntityStatePropertyValue(SourceStateTransmitter.java:110)
> > at > org.springframework.data.neo4j.support.mapping.SourceStateTransmitter.acces s$000(SourceStateTransmitter.java:39)
> > at > org.springframework.data.neo4j.support.mapping.SourceStateTransmitter$2.doW ithAssociation(SourceStateTransmitter.java:64)
> > at > org.springframework.data.mapping.model.BasicPersistentEntity.doWithAssociat ions(BasicPersistentEntity.java:185)
> > at > org.springframework.data.neo4j.support.mapping.SourceStateTransmitter.copyP ropertiesFrom(SourceStateTransmitter.java:60)
> > at > org.springframework.data.neo4j.support.mapping.Neo4jEntityConverterImpl.loa dEntity(Neo4jEntityConverterImpl.java:98)
> > at > org.springframework.data.neo4j.support.mapping.Neo4jEntityConverterImpl.rea d(Neo4jEntityConverterImpl.java:90)
> > at > org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister$CachedC onverter.read(Neo4jEntityPersister.java:168)
> > at > org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister.createE ntityFromState(Neo4jEntityPersister.java:189)
I resolved the issue by moving the @Indexed String name field into ResourceService instead of in Service (ResourceService extends Service). Now I can get through my unit test of relating the two different nodes. So I tried searching my other repository and seeing if it got persisted there and i don't get any errors but all fields are null except the nodeId (@GraphId). My method above is working with the serviceRepository but when I search the resourceRepository I get results but all fields are null
Even if I had the relationship to the resource it still outputs null. When i step thru adding the relationship both start and end nodes are correct and the relationship has an ID. template.save( res.addConsumesService(rservice) );
My method getConsumesServices() in my Resource class returns the set of ResourceServices @RelatedTo(type = "CONSUMES", direction = BOTH) Set<ResourceService> consumesServices;
When I step thru getConsumesServices() all values in consumesServices are null, but they are in there so something must be happening after template.save() or during the process right? No errors and unit test passes.. Any help is appreciated, thanks
> Thanks that fixed one of my problems. I haven't put any other properties in ConsumesResource because I was trying to start simple, I could add some properties but would like this to be working first. So I also have a relationship entity ResourceRelationship which is working after your advice, but when I try connecting a Resource to ResourceService I still have problems. The relationship entity ConsumesResource has an ID and appears to be saved.
> // from class ResourceService
> public ConsumesResource addConsumedResource(Resource res)
> {
> final ConsumesResource cr = new ConsumesResource(this, res);
> this.consumesRelationships.add(cr);
> return cr;
> }
> ////
> // test method
> Resource res = template.save( new Resource("123", "resourceTest") );
> ResourceService rservice = template.save( new ResourceService("101", "resourceService", "me", "http://example.com") );
> Resource rez = template.save( new resource("124", "resourceTest2") );
> ResourceService test = this.serviceRepository.findByName(rservice.getName()); // this is null..? i also tried "resourceService"
> Iterator<ResourceService> rTest = this.serviceRepository.findAll().iterator(); // this works...
> while(rTest.hasNext())
> {
> test = rTest.next();
> System.out.println("Service repository service: " + test.toString()); // prints out resourceService...
> System.out.println("Any Relationships? " + test.getConsumedResources().iterator().next().toString()); // this prints out relationship...
> }
> In this same test method I tried getting the resource from resourceRepository just to see what it would return
> Resource temp = this.resourceRepository.findByName("resourceTest"); // gives me the resource
> Could this have to do with ResourceService extending service (has name field)? I'm not sure what's going on..
> On Sunday, April 29, 2012 8:53:44 PM UTC-4, Michael Hunger wrote:
> The problem is that you have the same relationship twice in your class,
> once with the @RelatedToVia and once with @RelatedTo
> now you add it to both collections and save the entity.
> the collection consumesResource is saved first, creating neo4j relationships without any corresponding type information,
> then it tries to save consumesRelationships and in between tries to determine existing relationships of this rel-type and fails b/c the existing relationships have not (as expected any java type (in this case ConsumesResource) connected).
> if you don't store additional properties on ConsumesResource you don't need it
> and then you also don't need the @RelatedToVia collection
> in any other case it would be sensible only to fill consumesRelationships when adding Resources, and keeping consumesResource to null which is then ignored.
> HTH
> Michael
> Am 30.04.2012 um 02:34 schrieb Chris:
> > Hi, i'm trying to create a relationship between two different classes; Resource, and ResourceService. When I create the relationship I can see the start and end nodes are correct but the id is null.. my test has two repositories configured
> > // throws not found exception in test method > > Resource res = template.save( new Resource("123", "resourceTest") ); > > ResourceService rservice = template.save( new ResourceService("101", "resourceService", "me", "http://example.com") ); > > ConsumesResource cr = rservice.addConsumedResource(res); > > template.save( cr ); // start and end nodes are correct but id is null - throws exception
> > Here is the stack trace > > org.neo4j.graphdb.NotFoundException: '__type__' property not found for RelationshipImpl #11 of type 2 between Node[12] and Node[15]. > > at org.neo4j.kernel.impl.core.Primitive.newPropertyNotFoundException(Primitive .java:183) > > at org.neo4j.kernel.impl.core.Primitive.getProperty(Primitive.java:178) > > at org.neo4j.kernel.impl.core.RelationshipProxy.getProperty(RelationshipProxy. java:90) > > at org.springframework.data.neo4j.support.typerepresentation.AbstractIndexingT ypeRepresentationStrategy.getJavaType(AbstractIndexingTypeRepresentationStr ategy.java:89) > > at org.springframework.data.neo4j.support.mapping.TRSTypeAliasAccessor.readAli asFrom(TRSTypeAliasAccessor.java:39) > > at org.springframework.data.neo4j.support.mapping.TRSTypeAliasAccessor.readAli asFrom(TRSTypeAliasAccessor.java:29) > > at org.springframework.data.convert.DefaultTypeMapper.readType(DefaultTypeMapp er.java:72) > > at org.springframework.data.convert.DefaultTypeMapper.getDefaultedTypeToBeUsed (DefaultTypeMapper.java:116) > > at org.springframework.data.convert.DefaultTypeMapper.readType(DefaultTypeMapp er.java:93) > > at org.springframework.data.neo4j.support.mapping.Neo4jEntityConverterImpl.rea d(Neo4jEntityConverterImpl.java:74) > > at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister$CachedC onverter.read(Neo4jEntityPersister.java:168) > > at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister.createE ntityFromState(Neo4jEntityPersister.java:189) > > at org.springframework.data.neo4j.support.Neo4jTemplate.createEntityFromState( Neo4jTemplate.java:190) > > at org.springframework.data.neo4j.fieldaccess.GraphBackedEntityIterableWrapper .underlyingObjectToObject(GraphBackedEntityIterableWrapper.java:38) > > at org.springframework.data.neo4j.fieldaccess.GraphBackedEntityIterableWrapper .underlyingObjectToObject(GraphBackedEntityIterableWrapper.java:26) > > at org.neo4j.helpers.collection.IterableWrapper$MyIteratorWrapper.underlyingOb jectToObject(IterableWrapper.java:57) > > at org.neo4j.helpers.collection.IteratorWrapper.next(IteratorWrapper.java:47) > > at org.neo4j.helpers.collection.IteratorUtil.addToCollection(IteratorUtil.java :322) > > at org.neo4j.helpers.collection.IteratorUtil.addToCollection(IteratorUtil.java :339) > > at org.springframework.data.neo4j.fieldaccess.OneToNRelationshipEntityFieldAcc essorFactory$OneToNRelationshipEntityFieldAccessor.getValue(OneToNRelations hipEntityFieldAccessorFactory.java:119) > > at org.springframework.data.neo4j.fieldaccess.DefaultEntityState.getValue(Defa ultEntityState.java:97) > > at org.springframework.data.neo4j.support.mapping.SourceStateTransmitter.copyE ntityStatePropertyValue(SourceStateTransmitter.java:110) > > at org.springframework.data.neo4j.support.mapping.SourceStateTransmitter.acces s$000(SourceStateTransmitter.java:39) > > at org.springframework.data.neo4j.support.mapping.SourceStateTransmitter$2.doW ithAssociation(SourceStateTransmitter.java:64) > > at org.springframework.data.mapping.model.BasicPersistentEntity.doWithAssociat ions(BasicPersistentEntity.java:185) > > at org.springframework.data.neo4j.support.mapping.SourceStateTransmitter.copyP ropertiesFrom(SourceStateTransmitter.java:60) > > at org.springframework.data.neo4j.support.mapping.Neo4jEntityConverterImpl.loa dEntity(Neo4jEntityConverterImpl.java:98) > > at org.springframework.data.neo4j.support.mapping.Neo4jEntityConverterImpl.rea d(Neo4jEntityConverterImpl.java:90) > > at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister$CachedC onverter.read(Neo4jEntityPersister.java:168) > > at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister.createE ntityFromState(Neo4jEntityPersister.java:186) > > at org.springframework.data.neo4j.support.Neo4jTemplate.createEntityFromState( Neo4jTemplate.java:190) > > at org.springframework.data.neo4j.fieldaccess.RelationshipNodeFieldAccessorFac tory$RelationshipNodeFieldAccessor.getValue(RelationshipNodeFieldAccessorFa ctory.java:102) > > at org.springframework.data.neo4j.fieldaccess.DefaultEntityState.getValue(Defa ultEntityState.java:97) > > at org.springframework.data.neo4j.support.mapping.SourceStateTransmitter.copyE ntityStatePropertyValue(SourceStateTransmitter.java:110) > > at org.springframework.data.neo4j.support.mapping.SourceStateTransmitter.acces s$000(SourceStateTransmitter.java:39) > > at org.springframework.data.neo4j.support.mapping.SourceStateTransmitter$2.doW ithAssociation(SourceStateTransmitter.java:64) > > at org.springframework.data.mapping.model.BasicPersistentEntity.doWithAssociat ions(BasicPersistentEntity.java:185) > > at org.springframework.data.neo4j.support.mapping.SourceStateTransmitter.copyP ropertiesFrom(SourceStateTransmitter.java:60) > > at org.springframework.data.neo4j.support.mapping.Neo4jEntityConverterImpl.loa dEntity(Neo4jEntityConverterImpl.java:98) > > at org.springframework.data.neo4j.support.mapping.Neo4jEntityConverterImpl.rea d(Neo4jEntityConverterImpl.java:90) > > at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister$CachedC onverter.read(Neo4jEntityPersister.java:168)
with inherited fields and @Indexed you can specify on which level you want to index the field, either globally, on the class that defines the field, or the actual current instance. with @Indexed(level = GLOBAL, CLASS, INSTANCE)
I assume you use simple mapping (no AJ, just spring-data-neo4j). If you want to have related entities fetched you have to add @Fetch to the collection.
> I resolved the issue by moving the @Indexed String name field into ResourceService instead of in Service (ResourceService extends Service). Now I can get through my unit test of relating the two different nodes. So I tried searching my other repository and seeing if it got persisted there and i don't get any errors but all fields are null except the nodeId (@GraphId). My method above is working with the serviceRepository but when I search the resourceRepository I get results but all fields are null
> Will print out:
> Got resource service: null, null
> Even if I had the relationship to the resource it still outputs null. When i step thru adding the relationship both start and end nodes are correct and the relationship has an ID.
> template.save( res.addConsumesService(rservice) );
> My method getConsumesServices() in my Resource class returns the set of ResourceServices
> @RelatedTo(type = "CONSUMES", direction = BOTH)
> Set<ResourceService> consumesServices;
> When I step thru getConsumesServices() all values in consumesServices are null, but they are in there so something must be happening after template.save() or during the process right? No errors and unit test passes.. Any help is appreciated, thanks
I've never used github, i'll have to look into it.
Maybe i'm using an older version of SDN? @Index(level = GLOBAL) says GLOBAL cannot be resolved.
I have two repositories, resourceRepository and serviceRepository. I have a relationship entity ConsumesResource which relates Resource with ResourceService. Querying the serviceRepository I get the correct Resources, but if I query the resourceRepository I get null values for the ResourceService. When I step thru adding the relationship the Resource and ResourceService (start and end) nodes are correct.
@Test public void canBeRelated() { // throws not found exception in test method Resource res = template.save( new Resource("123", "resourceTest") ); Resource rez = template.save( new resource("124", "resourceTest2") ); ResourceService rservice = template.save( new ResourceService("101", "resourceService", "me", "http://example.com") ); template.save( rservice.addConsumedResource(res) ); template.save( rservice.addConsumedResource(rez) );
ResourceService test = this.serviceRepository.findByName(rservice.getName()); Iterator<Resource> ite = test.getConsumedResources().iterator(); while(ite.hasNext()) { Resource r = (Resource) ite.next(); System.out.println("Have resource! " + r.toString()); // this works assertEquals("Resource found thru service repo", r.getClass(), Resource.class); }
// template.save( res.addConsumesService(rservice) ); // output below is still [null, null]
Resource temp = this.resourceRepository.findByName("resourceTest"); Iterator<ResourceService> it = temp.getConsumesServices().iterator(); while(it.hasNext()) { ResourceService rs = (ResourceService) it.next(); System.out.println("Got resource service: " + rs.toString()); // All fields in rs are null except for nodeId(@GraphId) // output [name, uri] I get: [null, null] assertEquals("Resource service found", rs.getClass(), ResourceService.class); }
}
public class ReesourceService extends Service { @RelatedTo(elementClass = Resource.class, type = "CONSUMES") Set<Resource> consumesResource; // inputs
@RelatedToVia(elementClass = ConsumesResource.class, type = "CONSUMES") Set<ConsumesResource> consumesRelationships;
public Iterable<Resource> getConsumedResources() { return this.consumesResource; }
public ConsumesResource addConsumedResource(Resource res) { this.consumesResource.add(res); ConsumesResource cr = new ConsumesResource(this, res); this.consumesRelationships.add(cr); return cr; } ...
the reason for the behavior you see is that the id is indexed only for Services (b.c. the field is in that class and the default level is Level.CLASS).
If you want to have your ResourceRepository return the resources, you have to use level=Level.INSTANCE.
this is because the two indexes have different names, one is called "Service" the other "Resource" according to your class-names.
> I've never used github, i'll have to look into it.
> Maybe i'm using an older version of SDN? @Index(level = GLOBAL) says GLOBAL cannot be resolved.
> I have two repositories, resourceRepository and serviceRepository. I have a relationship entity ConsumesResource which relates Resource with ResourceService. Querying the serviceRepository I get the correct Resources, but if I query the resourceRepository I get null values for the ResourceService. When I step thru adding the relationship the Resource and ResourceService (start and end) nodes are correct.
> @Test
> public void canBeRelated()
> {
> // throws not found exception in test method
> Resource res = template.save( new Resource("123", "resourceTest") );
> Resource rez = template.save( new resource("124", "resourceTest2") );
> ResourceService rservice = template.save( new ResourceService("101", "resourceService", "me", "http://example.com") );
> template.save( rservice.addConsumedResource(res) );
> template.save( rservice.addConsumedResource(rez) );
> ResourceService test = this.serviceRepository.findByName(rservice.getName()); > Iterator<Resource> ite = test.getConsumedResources().iterator();
> while(ite.hasNext())
> {
> Resource r = (Resource) ite.next();
> System.out.println("Have resource! " + r.toString()); // this works > assertEquals("Resource found thru service repo", r.getClass(), Resource.class);
> }
> // template.save( res.addConsumesService(rservice) ); // output below is still [null, null]
> Resource temp = this.resourceRepository.findByName("resourceTest");
> Iterator<ResourceService> it = temp.getConsumesServices().iterator();
> while(it.hasNext())
> {
> ResourceService rs = (ResourceService) it.next();
> System.out.println("Got resource service: " + rs.toString()); // All fields in rs are null except for nodeId(@GraphId)
> // output [name, uri] I get: [null, null]
> assertEquals("Resource service found", rs.getClass(), ResourceService.class);
> }
> }
> public class ReesourceService extends Service
> { > @RelatedTo(elementClass = Resource.class, type = "CONSUMES")
> Set<Resource> consumesResource; // inputs
> @RelatedToVia(elementClass = ConsumesResource.class, type = "CONSUMES")
> Set<ConsumesResource> consumesRelationships;
That was my assumption in my third post, when I tried
this.serviceRepository.findByName("resourceService"); I wouldn't get anything back - but I could see the service if i did findAll and printed them out.
so I commented name out in Service class and moved it to ResourceService which solved the problem - I implemented the INSTANCE level index and is still working. my serviceRepository is returning the correct resources, but when I lookup thru the resourceRepository it has ResourceServices but they are filled with null values. I want to be able to return ResourceServices from my resourceRepository (not woking), and return Resources from my serviceRepository (working). It looks like it's a similar problem with the name field index level, ResourceService is found but is of class Service so all fields are null?
On Monday, April 30, 2012 9:25:19 PM UTC-4, Michael Hunger wrote:
> Which version of SDN are you using?
> the reason for the behavior you see is that the id is indexed only for > Services (b.c. the field is in that class and the default level is > Level.CLASS). > If you want to have your ResourceRepository return the resources, you have > to use level=Level.INSTANCE.
> this is because the two indexes have different names, one is called > "Service" the other "Resource" according to your class-names.
> Michael
> Am 01.05.2012 um 03:14 schrieb Chris:
> > Hi Michael,
> > I've never used github, i'll have to look into it.
> > Maybe i'm using an older version of SDN? @Index(level = GLOBAL) says > GLOBAL cannot be resolved.
> > I have two repositories, resourceRepository and serviceRepository. I > have a relationship entity ConsumesResource which relates Resource with > ResourceService. Querying the serviceRepository I get the correct > Resources, but if I query the resourceRepository I get null values for the > ResourceService. When I step thru adding the relationship the Resource and > ResourceService (start and end) nodes are correct.
> > @Test > > public void canBeRelated() > > { > > // throws not found exception in test method > > Resource res = template.save( new Resource("123", "resourceTest") ); > > Resource rez = template.save( new resource("124", "resourceTest2") > ); > > ResourceService rservice = template.save( new ResourceService("101", > "resourceService", "me", "http://example.com") ); > > template.save( rservice.addConsumedResource(res) ); > > template.save( rservice.addConsumedResource(rez) );
> > ResourceService test = > this.serviceRepository.findByName(rservice.getName()); > > Iterator<Resource> ite = test.getConsumedResources().iterator(); > > while(ite.hasNext()) > > { > > Resource r = (Resource) ite.next(); > > System.out.println("Have resource! " + r.toString()); // this > works > > assertEquals("Resource found thru service repo", r.getClass(), > Resource.class); > > }
> > // template.save( res.addConsumesService(rservice) ); // output > below is still [null, null]
> > Resource temp = > this.resourceRepository.findByName("resourceTest"); > > Iterator<ResourceService> it = > temp.getConsumesServices().iterator(); > > while(it.hasNext()) > > { > > ResourceService rs = (ResourceService) it.next(); > > System.out.println("Got resource service: " + > rs.toString()); // All fields in rs are null except for nodeId(@GraphId) > > // output [name, uri] I get: [null, null] > > assertEquals("Resource service found", rs.getClass(), > ResourceService.class); > > } > > }
> > public class ReesourceService extends Service > > { > > @RelatedTo(elementClass = Resource.class, type = "CONSUMES") > > Set<Resource> consumesResource; // inputs
did you see this in my email (2 responses back)? quote:
I assume you use simple mapping (no AJ, just spring-data-neo4j). If you want to have related entities fetched you have to add @Fetch to the collection.
> That was my assumption in my third post, when I tried
> this.serviceRepository.findByName("resourceService"); I wouldn't get anything back - but I could see the service if i did findAll and printed them out.
> so I commented name out in Service class and moved it to ResourceService which solved the problem - I implemented the INSTANCE level index and is still working. my serviceRepository is returning the correct resources, but when I lookup thru the resourceRepository it has ResourceServices but they are filled with null values. I want to be able to return ResourceServices from my resourceRepository (not woking), and return Resources from my serviceRepository (working). It looks like it's a similar problem with the name field index level, ResourceService is found but is of class Service so all fields are null?
> Really appreciate the help Michael!
> On Monday, April 30, 2012 9:25:19 PM UTC-4, Michael Hunger wrote:
> Which version of SDN are you using?
> the reason for the behavior you see is that the id is indexed only for Services (b.c. the field is in that class and the default level is Level.CLASS). > If you want to have your ResourceRepository return the resources, you have to use level=Level.INSTANCE.
> this is because the two indexes have different names, one is called "Service" the other "Resource" according to your class-names.
> Michael
> Am 01.05.2012 um 03:14 schrieb Chris:
> > Hi Michael,
> > I've never used github, i'll have to look into it.
> > Maybe i'm using an older version of SDN? @Index(level = GLOBAL) says GLOBAL cannot be resolved.
> > I have two repositories, resourceRepository and serviceRepository. I have a relationship entity ConsumesResource which relates Resource with ResourceService. Querying the serviceRepository I get the correct Resources, but if I query the resourceRepository I get null values for the ResourceService. When I step thru adding the relationship the Resource and ResourceService (start and end) nodes are correct.
> > @Test > > public void canBeRelated() > > { > > // throws not found exception in test method > > Resource res = template.save( new Resource("123", "resourceTest") ); > > Resource rez = template.save( new resource("124", "resourceTest2") ); > > ResourceService rservice = template.save( new ResourceService("101", "resourceService", "me", "http://example.com") ); > > template.save( rservice.addConsumedResource(res) ); > > template.save( rservice.addConsumedResource(rez) );
> > ResourceService test = this.serviceRepository.findByName(rservice.getName()); > > Iterator<Resource> ite = test.getConsumedResources().iterator(); > > while(ite.hasNext()) > > { > > Resource r = (Resource) ite.next(); > > System.out.println("Have resource! " + r.toString()); // this works > > assertEquals("Resource found thru service repo", r.getClass(), Resource.class); > > }
> > // template.save( res.addConsumesService(rservice) ); // output below is still [null, null]
> > Resource temp = this.resourceRepository.findByName("resourceTest"); > > Iterator<ResourceService> it = temp.getConsumesServices().iterator(); > > while(it.hasNext()) > > { > > ResourceService rs = (ResourceService) it.next(); > > System.out.println("Got resource service: " + rs.toString()); // All fields in rs are null except for nodeId(@GraphId) > > // output [name, uri] I get: [null, null] > > assertEquals("Resource service found", rs.getClass(), ResourceService.class); > > } > > }
> > public class ReesourceService extends Service > > { > > @RelatedTo(elementClass = Resource.class, type = "CONSUMES") > > Set<Resource> consumesResource; // inputs
On Tuesday, May 1, 2012 8:45:45 AM UTC-4, Michael Hunger wrote:
> Chris,
> did you see this in my email (2 responses back)? quote:
> I assume you use simple mapping (no AJ, just spring-data-neo4j). If you > want to have related entities fetched you have to add @Fetch to the > collection.
> Michael
> Am 01.05.2012 um 14:08 schrieb Chris:
> 2.0.1.RELEASE. Level is working now, thanks.
> That was my assumption in my third post, when I tried
> this.serviceRepository.findByName("resourceService"); I wouldn't get > anything back - but I could see the service if i did findAll and printed > them out.
> so I commented name out in Service class and moved it to ResourceService > which solved the problem - I implemented the INSTANCE level index and is > still working. my serviceRepository is returning the correct resources, but > when I lookup thru the resourceRepository it has ResourceServices but they > are filled with null values. I want to be able to return ResourceServices > from my resourceRepository (not woking), and return Resources from my > serviceRepository (working). It looks like it's a similar problem with the > name field index level, ResourceService is found but is of class Service so > all fields are null?
> Really appreciate the help Michael!
> On Monday, April 30, 2012 9:25:19 PM UTC-4, Michael Hunger wrote:
>> Which version of SDN are you using?
>> the reason for the behavior you see is that the id is indexed only for >> Services (b.c. the field is in that class and the default level is >> Level.CLASS). >> If you want to have your ResourceRepository return the resources, you >> have to use level=Level.INSTANCE.
>> this is because the two indexes have different names, one is called >> "Service" the other "Resource" according to your class-names.
>> Michael
>> Am 01.05.2012 um 03:14 schrieb Chris:
>> > Hi Michael,
>> > I've never used github, i'll have to look into it.
>> > Maybe i'm using an older version of SDN? @Index(level = GLOBAL) says >> GLOBAL cannot be resolved.
>> > I have two repositories, resourceRepository and serviceRepository. I >> have a relationship entity ConsumesResource which relates Resource with >> ResourceService. Querying the serviceRepository I get the correct >> Resources, but if I query the resourceRepository I get null values for the >> ResourceService. When I step thru adding the relationship the Resource and >> ResourceService (start and end) nodes are correct.
>> > @Test >> > public void canBeRelated() >> > { >> > // throws not found exception in test method >> > Resource res = template.save( new Resource("123", "resourceTest") >> ); >> > Resource rez = template.save( new resource("124", "resourceTest2") >> ); >> > ResourceService rservice = template.save( new >> ResourceService("101", "resourceService", "me", "http://example.com") ); >> > template.save( rservice.addConsumedResource(res) ); >> > template.save( rservice.addConsumedResource(rez) );
>> > ResourceService test = >> this.serviceRepository.findByName(rservice.getName()); >> > Iterator<Resource> ite = test.getConsumedResources().iterator(); >> > while(ite.hasNext()) >> > { >> > Resource r = (Resource) ite.next(); >> > System.out.println("Have resource! " + r.toString()); // this >> works >> > assertEquals("Resource found thru service repo", r.getClass(), >> Resource.class); >> > }
>> > // template.save( res.addConsumesService(rservice) ); // output >> below is still [null, null]
>> > Resource temp = >> this.resourceRepository.findByName("resourceTest"); >> > Iterator<ResourceService> it = >> temp.getConsumesServices().iterator(); >> > while(it.hasNext()) >> > { >> > ResourceService rs = (ResourceService) it.next(); >> > System.out.println("Got resource service: " + >> rs.toString()); // All fields in rs are null except for nodeId(@GraphId) >> > // output [name, uri] I get: [null, null] >> > assertEquals("Resource service found", rs.getClass(), >> ResourceService.class); >> > } >> > }
>> > public class ReesourceService extends Service >> > { >> > @RelatedTo(elementClass = Resource.class, type = "CONSUMES") >> > Set<Resource> consumesResource; // inputs
On Tuesday, May 1, 2012 8:45:45 AM UTC-4, Michael Hunger wrote:
> Chris,
> did you see this in my email (2 responses back)? quote:
> I assume you use simple mapping (no AJ, just spring-data-neo4j). If you > want to have related entities fetched you have to add @Fetch to the > collection.
> Michael
> Am 01.05.2012 um 14:08 schrieb Chris:
> 2.0.1.RELEASE. Level is working now, thanks.
> That was my assumption in my third post, when I tried
> this.serviceRepository.findByName("resourceService"); I wouldn't get > anything back - but I could see the service if i did findAll and printed > them out.
> so I commented name out in Service class and moved it to ResourceService > which solved the problem - I implemented the INSTANCE level index and is > still working. my serviceRepository is returning the correct resources, but > when I lookup thru the resourceRepository it has ResourceServices but they > are filled with null values. I want to be able to return ResourceServices > from my resourceRepository (not woking), and return Resources from my > serviceRepository (working). It looks like it's a similar problem with the > name field index level, ResourceService is found but is of class Service so > all fields are null?
> Really appreciate the help Michael!
> On Monday, April 30, 2012 9:25:19 PM UTC-4, Michael Hunger wrote:
>> Which version of SDN are you using?
>> the reason for the behavior you see is that the id is indexed only for >> Services (b.c. the field is in that class and the default level is >> Level.CLASS). >> If you want to have your ResourceRepository return the resources, you >> have to use level=Level.INSTANCE.
>> this is because the two indexes have different names, one is called >> "Service" the other "Resource" according to your class-names.
>> Michael
>> Am 01.05.2012 um 03:14 schrieb Chris:
>> > Hi Michael,
>> > I've never used github, i'll have to look into it.
>> > Maybe i'm using an older version of SDN? @Index(level = GLOBAL) says >> GLOBAL cannot be resolved.
>> > I have two repositories, resourceRepository and serviceRepository. I >> have a relationship entity ConsumesResource which relates Resource with >> ResourceService. Querying the serviceRepository I get the correct >> Resources, but if I query the resourceRepository I get null values for the >> ResourceService. When I step thru adding the relationship the Resource and >> ResourceService (start and end) nodes are correct.
>> > @Test >> > public void canBeRelated() >> > { >> > // throws not found exception in test method >> > Resource res = template.save( new Resource("123", "resourceTest") >> ); >> > Resource rez = template.save( new resource("124", "resourceTest2") >> ); >> > ResourceService rservice = template.save( new >> ResourceService("101", "resourceService", "me", "http://example.com") ); >> > template.save( rservice.addConsumedResource(res) ); >> > template.save( rservice.addConsumedResource(rez) );
>> > ResourceService test = >> this.serviceRepository.findByName(rservice.getName()); >> > Iterator<Resource> ite = test.getConsumedResources().iterator(); >> > while(ite.hasNext()) >> > { >> > Resource r = (Resource) ite.next(); >> > System.out.println("Have resource! " + r.toString()); // this >> works >> > assertEquals("Resource found thru service repo", r.getClass(), >> Resource.class); >> > }
>> > // template.save( res.addConsumesService(rservice) ); // output >> below is still [null, null]
>> > Resource temp = >> this.resourceRepository.findByName("resourceTest"); >> > Iterator<ResourceService> it = >> temp.getConsumesServices().iterator(); >> > while(it.hasNext()) >> > { >> > ResourceService rs = (ResourceService) it.next(); >> > System.out.println("Got resource service: " + >> rs.toString()); // All fields in rs are null except for nodeId(@GraphId) >> > // output [name, uri] I get: [null, null] >> > assertEquals("Resource service found", rs.getClass(), >> ResourceService.class); >> > } >> > }
>> > public class ReesourceService extends Service >> > { >> > @RelatedTo(elementClass = Resource.class, type = "CONSUMES") >> > Set<Resource> consumesResource; // inputs