I am new to Neo4J and I probably have a simple question.
My application has NodeEntity, the property (name) is annotated using @Indexed (unique = true) to achieve uniqueness, as in JPA, using @Column (unique = true).
My problem is that when I save an object with a name that already exists in my chart, it still works fine. But I was expecting some kind of exception here ...?! Here is an overview of the main code:
@NodeEntity public abstract class BaseEntity implements Identifiable { @GraphId private Long entityId; ... } public class Role extends BaseEntity { @Indexed(unique = true) private String name; ... } public interface RoleRepository extends GraphRepository<Role> { Role findByName(String name); } @Service public class RoleServiceImpl extends BaseEntityServiceImpl<Role> implements { private RoleRepository repository; @Override @Transactional public T save(final T entity) { return getRepository().save(entity); } }
And this is my test:
@Test public void testNameUniqueIndex() { final List<Role> roles = Lists.newLinkedList(service.findAll()); final String existingName = roles.get(0).getName(); Role newRole = new Role.Builder(existingName).build(); newRole = service.save(newRole); }
That I expect something to go wrong! How can I ensure the uniqueness of a property without checking it for myself?
PS: I use neo4j 1.8.M07, spring -data-neo4j 2.1.0.BUILD-SNAPSHOT and Spring 3.1.2.RELEASE.
source share