SDN 4 + OGM 1.1.1 @Index(unique = true)无法正常工作 [英] SDN 4 + OGM 1.1.1 @Index(unique = true) is not working
问题描述
我知道之前曾有人问过这个问题,但是看起来好像没有SDN 4
和OGM 1.1.1
I know this question has been asked before, but looks like not with SDN 4
and OGM 1.1.1
这是我在@NodeEntity
@NodeEntity
public class Company {
@GraphId
private Long id;
@Index(unique = true)
private String name;
private String description;
这是repo
@Repository
public interface CompanyRepository extends GraphRepository<Company> {
Company findByName(String name);
我有一个带有方法的单元测试类
and I have a unit test class with methods
@Autowired
private CompanyRepository companyRepository;
@Before
public void setUp() throws Exception {
companyRepository.deleteAll();
Company company = new Company();
company.setName("Westpac");
company.setDescription("blah");
companyRepository.save(company);
}
@Test
public void testIndexUnique() throws Exception{
Company company = new Company();
company.setName("Westpac");
company.setDescription("blah blah");
companyRepository.save(company);
}
@Test
实际上通过了,这不是我所期望的.假定失败,因为具有name
字段Westpac
的Company
已经存在.
The @Test
actually passed, which is not what I am expecting. It suppose to be failed since a Company
with name
field Westpac
already exist.
是我遗漏了任何东西还是错误理解了@Index
.
Am I missing anything or understand this @Index
wrongly.
谢谢
推荐答案
@Index isn't supported in SDN 4- http://docs.spring.io/spring-data/neo4j/docs/4.0.0.RC2/reference/html/#_index_management_in_spring_data_neo4j_4
或OGM- http://neo4j.com/docs/ogm/java/stable/#_ indexing
您必须自己设置索引(或通过Neo4jTemplate/Session使用Cypher)
You'll have to set up the index yourself (or using Cypher via the Neo4jTemplate/Session)
这篇关于SDN 4 + OGM 1.1.1 @Index(unique = true)无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!