SDN 4 + OGM 1.1.1 @Index(unique = true) is not working

核能气质少年 提交于 2019-12-11 11:28:02

问题


I know this question has been asked before, but looks like not with SDN 4 and OGM 1.1.1

Here is my code on the @NodeEntity

@NodeEntity
public class Company {

    @GraphId
    private Long id;

    @Index(unique = true)
    private String name;

    private String description;

Here is the 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);
}

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.

Am I missing anything or understand this @Index wrongly.

Thanks,


回答1:


@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

or the OGM- http://neo4j.com/docs/ogm/java/stable/#_indexing

You'll have to set up the index yourself (or using Cypher via the Neo4jTemplate/Session)



来源:https://stackoverflow.com/questions/32388724/sdn-4-ogm-1-1-1-indexunique-true-is-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!