SpringData Neo4J REST:使用@Indexed(unique=true)时出现运行时异常
我通过REST使用SpringData和Neo4j,当我添加@Indexed(unique=true)时,我看到了一个异常。这不会在embedded中引发异常,如果删除unique=true,也不会在REST中引发异常。即使数据库为空(没有节点和索引),也会发生这种情况 有什么想法吗SpringData Neo4J REST:使用@Indexed(unique=true)时出现运行时异常,neo4j,spring-data-neo4j,Neo4j,Spring Data Neo4j,我通过REST使用SpringData和Neo4j,当我添加@Indexed(unique=true)时,我看到了一个异常。这不会在embedded中引发异常,如果删除unique=true,也不会在REST中引发异常。即使数据库为空(没有节点和索引),也会发生这种情况 有什么想法吗 package com.mycompany; import org.springframework.data.neo4j.annotation.GraphId; import org.springframewor
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;
}
}
为了完整起见,下面是测试代码:
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);
}
}
似乎是一个已知的bug,请参见。
无论如何,例外是关于_类型_索引,它与您在类中定义的索引无关,SDN使用它按类名检索对象
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);
}
}