SDN 4 + OGM 1.1.1 @Index(unique = true)无法正常工作 [英] SDN 4 + OGM 1.1.1 @Index(unique = true) is not working

查看:215
本文介绍了SDN 4 + OGM 1.1.1 @Index(unique = true)无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道之前曾有人问过这个问题,但是看起来好像没有SDN 4OGM 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字段WestpacCompany已经存在.

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 @

@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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆