Reputation: 1655
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,
Upvotes: 1
Views: 224
Reputation: 19373
@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)
Upvotes: 2