在尝试将我的节点检索回我的域对象时,我收到了这个奇怪的错误:
Exception in thread "main" java.lang.StackOverflowError
at sun.nio.ch.NativeThreadSet.remove(NativeThreadSet.java:76)
at sun.nio.ch.FileChannelImpl.read(FileChannelImpl.java:678)
at org.neo4j.kernel.impl.nioneo.store.PersistenceRow.readFullWindow(PersistenceRow.java:158)
at org.neo4j.kernel.impl.nioneo.store.PersistenceRow$State$1.transition(PersistenceRow.java:115)
at org.neo4j.kernel.impl.nioneo.store.PersistenceRow.lock(PersistenceRow.java:59)
at org.neo4j.kernel.impl.nioneo.store.PersistenceWindowPool.acquire(PersistenceWindowPool.java:193)
at org.neo4j.kernel.impl.nioneo.store.CommonAbstractStore.acquireWindow(CommonAbstractStore.java:520)
at org.neo4j.kernel.impl.nioneo.store.NodeStore.getRecord(NodeStore.java:76)
at org.neo4j.kernel.impl.nioneo.xa.ReadTransaction.nodeLoadProperties(ReadTransaction.java:239)
at org.neo4j.kernel.impl.persistence.PersistenceManager.loadNodeProperties(PersistenceManager.java:113)
at org.neo4j.kernel.impl.core.NodeManager.loadProperties(NodeManager.java:682)
at org.neo4j.kernel.impl.core.NodeImpl.loadProperties(NodeImpl.java:132)
at org.neo4j.kernel.impl.core.Primitive.ensureFullProperties(Primitive.java:584)
at org.neo4j.kernel.impl.core.Primitive.ensureFullProperties(Primitive.java:567)
at org.neo4j.kernel.impl.core.Primitive.getProperty(Primitive.java:153)
at org.neo4j.kernel.impl.core.NodeImpl.getProperty(NodeImpl.java:51)
at org.neo4j.kernel.impl.core.NodeProxy.getProperty(NodeProxy.java:155)
at org.springframework.data.neo4j.support.typerepresentation.AbstractIndexingTypeRepresentationStrategy.readAliasFrom(AbstractIndexingTypeRepresentationStrategy.java:106)
at org.springframework.data.neo4j.support.mapping.TRSTypeAliasAccessor.readAliasFrom(TRSTypeAliasAccessor.java:36)
at org.springframework.data.neo4j.support.mapping.TRSTypeAliasAccessor.readAliasFrom(TRSTypeAliasAccessor.java:26)
at org.springframework.data.convert.DefaultTypeMapper.readType(DefaultTypeMapper.java:96)
at org.springframework.data.convert.DefaultTypeMapper.getDefaultedTypeToBeUsed(DefaultTypeMapper.java:144)
at org.springframework.data.convert.DefaultTypeMapper.readType(DefaultTypeMapper.java:121)
at org.springframework.data.neo4j.support.mapping.Neo4jEntityConverterImpl.read(Neo4jEntityConverterImpl.java:76)
at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister$CachedConverter.read(Neo4jEntityPersister.java:170)
at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister.createEntityFromState(Neo4jEntityPersister.java:189)
at org.springframework.data.neo4j.support.Neo4jTemplate.createEntityFromState(Neo4jTemplate.java:180)
at org.springframework.data.neo4j.fieldaccess.RelationshipNodeFieldAccessorFactory$RelationshipNodeFieldAccessor.getValue(RelationshipNodeFieldAccessorFactory.java:102)
at org.springframework.data.neo4j.fieldaccess.DefaultEntityState.getValue(DefaultEntityState.java:97)
at org.springframework.data.neo4j.support.mapping.SourceStateTransmitter.copyEntityStatePropertyValue(SourceStateTransmitter.java:90)
at org.springframework.data.neo4j.support.mapping.SourceStateTransmitter.access$000(SourceStateTransmitter.java:40)
at org.springframework.data.neo4j.support.mapping.SourceStateTransmitter$2.doWithAssociation(SourceStateTransmitter.java:61)
at org.springframework.data.mapping.model.BasicPersistentEntity.doWithAssociations(BasicPersistentEntity.java:207)
at org.springframework.data.neo4j.support.mapping.SourceStateTransmitter.copyPropertiesFrom(SourceStateTransmitter.java:57)
at org.springframework.data.neo4j.support.mapping.Neo4jEntityConverterImpl.loadEntity(Neo4jEntityConverterImpl.java:100)
at org.springframework.data.neo4j.support.mapping.Neo4jEntityConverterImpl.read(Neo4jEntityConverterImpl.java:92)
at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister$CachedConverter.read(Neo4jEntityPersister.java:170)
at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister.createEntityFromState(Neo4jEntityPersister.java:192)
at org.springframework.data.neo4j.support.Neo4jTemplate.createEntityFromState(Neo4jTemplate.java:180)
at org.springframework.data.neo4j.fieldaccess.GraphBackedEntityIterableWrapper.underlyingObjectToObject(GraphBackedEntityIterableWrapper.java:41)
at org.springframework.data.neo4j.fieldaccess.GraphBackedEntityIterableWrapper.underlyingObjectToObject(GraphBackedEntityIterableWrapper.java:27)
at org.neo4j.helpers.collection.IterableWrapper$MyIteratorWrapper.underlyingObjectToObject(IterableWrapper.java:57)
at org.neo4j.helpers.collection.IteratorWrapper.next(IteratorWrapper.java:47)
at org.neo4j.helpers.collection.IteratorUtil.addToCollection(IteratorUtil.java:324)
at org.neo4j.helpers.collection.IteratorUtil.addToCollection(IteratorUtil.java:341)
at org.springframework.data.neo4j.fieldaccess.RelatedToViaCollectionFieldAccessorFactory$RelatedToViaCollectionFieldAccessor.getValue(RelatedToViaCollectionFieldAccessorFactory.java:122)
at org.springframework.data.neo4j.fieldaccess.DefaultEntityState.getValue(DefaultEntityState.java:97)
例如,这是我的cypher查询,它试图获取用户节点实体:
public MyUser getUserByUserId(String userId){
Long t1 = System.currentTimeMillis();
if(existsUserByUserId(userId)){
HashedMap params = new HashedMap();
params.put("userId", userId);
String query = "START x=node:searchByUserId(userId = {userId})" +
" RETURN x";
Result<Map<String,Object>> result = neo4jTemplate.query(query, params);
MyUser user = result.to(MyUser.class).single();
Long t2 = System.currentTimeMillis();
logger.info("get user by user id exec time: " + (t2-t1) + " ms");
return user;
}
Long t2 = System.currentTimeMillis();
logger.info("get user by id exec time: " + (t2-t1) + " ms");
return null;
}
其中searchByUserId
是节点索引,existsUserByUserId
是帮助方法,用于检查指定的用户是否存在。问题是,当我尝试调用result.to()方法时,我会随机获得此错误。随机我的意思是我总是没有得到这个错误。更具体地说,我使用本机Neo4j Java API插入了所有节点/关系,现在我正在尝试使用Spring Data Neo4j(存储库方法)检索这些对象。这就是我插入节点实体的方式:
public Node createAndIndexMyUserNode(MyUser user){
Map<String,Object> properties = new HashMap<String, Object>();
properties.put("userId", user.getUserId());
properties.put("baseID" , user.getBaseID());
properties.put("__type__", MyUser.class.getName());
properties.put("canUpdate", false);
Node node = neo4jTemplate.getOrCreateNode("searchByUserId", "userId", user.getTwitterId(), properties);
return node;
}
这可能是问题,但我不知道如何解决它。我怀疑糟糕的数据库关闭或关系创建(之后)也可能是一个原因,但我不确定。 This是我“手动”插入所有节点而不是使用存储库保存方法的原因。有什么建议或想法吗?
提前谢谢大家!