cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

I want to know how to eliminate duplicate nodes in neo4j using spring boot without using merge clause

I have created a pojo class and set up a structure how nodes should be created in neo4j. Using .save method which is inbuilt in neo4jRepository i am sending data using postman.
public Book addBook(Book book) {
return repository.save(book);
}
@PostMapping("/addBook")
public Classifier addingClassifier(@RequestBody Book book)) {
return bookService.addBook(book);
}

if i send same data using postman then neo4j is creating duplicate nodes. How to stop creating duplicate nodes.

8 REPLIES 8

use a unique constraint.

tried with unique constraint but it is of no use. It did not stop creating duplicate nodes.

By definition a unique constraint prevents duplication. I guess you're applying it not correctly.

No, I think I am using it correctly.

@NodeEntity
public class Book {

@Id
@GeneratedValue
private Long id;

@Index(unique = true)
private String name;

@Index(unique = true)
@Relationship(type = "Comprises_Of",direction = Relationship.OUTGOING)
private Set<Publishers> publishers;

}

what constraints do you actually have in the db: call db.constraints() ?

2X_4_4787655045308c53257c9da66d9154326c503fc5.jpeg

no constraints are applied to the fields.

@Index(Unique = true) is not working in the expected way. Please verify how to apply the unique constraint in spring boot code and let me know.

why not just fire a create constraint on .... statement directly to the database and you're done?