0

我正在通过 REST 使用 SpringData 和 Neo4j,当我添加 @Indexed(unique=true) 时我看到了一个异常。这不会在嵌入式中引发异常,如果我删除 unique=true,它不会在 REST 中引发异常。即使数据库是空的(没有节点也没有索引),它也会发生。

有任何想法吗?

package com.mycompany;

import org.springframework.data.neo4j.annotation.GraphId;
import org.springframework.data.neo4j.annotation.Indexed;
import org.springframework.data.neo4j.annotation.NodeEntity;

@NodeEntity
public class Person {
  @GraphId
  private Long id;

  @Indexed(unique=true) private String name; // <<<-- does not error if I remove unique-true)

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public Long getId() {
    return id;
  }

  public void setId(Long id) {
    this.id = id;
  }

  @Override
  public int hashCode() {
    int hash = 7;
    hash = 23 * hash + (this.name != null ? this.name.hashCode() : 0);
    return hash;
  }

  @Override
  public boolean equals(Object obj) {
    if (obj == null) {
      return false;
    }
    if (getClass() != obj.getClass()) {
      return false;
    }
    final Person other = (Person) obj;
    if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
      return false;
    }
    return true;
  }

}

这是异常跟踪:

java.lang.RuntimeException: Error adding element 10 className com.mycompany.Person to index __types__
    at org.neo4j.rest.graphdb.ExecutingRestAPI.addToIndex(ExecutingRestAPI.java:397)
    at org.neo4j.rest.graphdb.RestAPIFacade.addToIndex(RestAPIFacade.java:166)
    at org.neo4j.rest.graphdb.index.RestIndex.add(RestIndex.java:60)
    at org.springframework.data.neo4j.support.typerepresentation.AbstractIndexingTypeRepresentationStrategy.add(AbstractIndexingTypeRepresentationStrategy.java:123)
    at org.springframework.data.neo4j.support.typerepresentation.AbstractIndexingTypeRepresentationStrategy.addToTypesIndex(AbstractIndexingTypeRepresentationStrategy.java:115)
    at org.springframework.data.neo4j.support.typerepresentation.AbstractIndexingTypeRepresentationStrategy.writeTypeTo(AbstractIndexingTypeRepresentationStrategy.java:63)
    at org.springframework.data.neo4j.support.mapping.TRSTypeAliasAccessor.writeTypeTo(TRSTypeAliasAccessor.java:46)
    at org.springframework.data.neo4j.support.mapping.TRSTypeAliasAccessor.writeTypeTo(TRSTypeAliasAccessor.java:26)
    at org.springframework.data.convert.DefaultTypeMapper.writeType(DefaultTypeMapper.java:199)
    at org.springframework.data.convert.DefaultTypeMapper.writeType(DefaultTypeMapper.java:186)
    at org.springframework.data.neo4j.support.mapping.Neo4jEntityConverterImpl.write(Neo4jEntityConverterImpl.java:165)
    at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister$CachedConverter.write(Neo4jEntityPersister.java:179)
    at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister.persist(Neo4jEntityPersister.java:243)
    at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister.persist(Neo4jEntityPersister.java:231)
    at org.springframework.data.neo4j.support.Neo4jTemplate.save(Neo4jTemplate.java:294)
    at org.springframework.data.neo4j.support.Neo4jTemplate.save(Neo4jTemplate.java:288)
    at com.mycompany.NeoTest.testSomething(NeoTest.java:28)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    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.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)
    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.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

为了完整起见,这里是测试代码:

package com.mycompany;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;

import com.mycompany.Person;

import static org.junit.Assert.*;

@ContextConfiguration(locations = "classpath:testContext.xml")
@RunWith(SpringJUnit4ClassRunner.class)
public class NeoTest {

  @Autowired
  Neo4jTemplate template;

  @Test
  //@Transactional
  public void testSomething() {

    Person add = new Person();
    add.setName("Jorgan Jorgansen");
    add = template.save(add); 

    Person other = template.findOne(add.getId(), Person.class);
    assertNotNull("Retrieved entity is non-null", other);
    assertEquals("Retrieved entity equals saved entity", add, other);

  }
}
4

1 回答 1

0

似乎是一个已知的错误,请参阅此链接。无论如何,例外是关于 __types__ 索引,它与您在类中定义的索引无关,SDN 使用它按类名检索对象。

于 2013-10-05T07:05:29.640 回答