I have turned a part of the petclinic example to use spring data.
I am learning and testing the Crud/JpaRepository methods. It is very good. Thanks to Spring Team.
But I found a bug. The delete method is working fine as long the record hasn`t any objects of the many to many table. In the petclinic example we have a table called vet_specialties. So if the record in vets doesn`t have any references in vet_specialties the delete metod is fine. But if the vets record has a reference in vet_specialties we have a problem because the JpaRepository.delete(id) will remove all the records in the Vets table that has a similar reference.
id first name last name Specialties
1 James Carter
2 Helen Leary radiology
3 Linda Douglas surgery dentistry
4 Rafael Ortega surgery
5 Henry Stevens radiology
6 Sharon Jenkins

e.g. if JpaRepository.delete(2) then two records will be deleted row number 2 and row number 4.

id first name last name Specialties
1 James Carter
3 Linda Douglas surgery dentistry
5 Henry Stevens radiology
6 Sharon Jenkins

This is bug. only row number 2 should be deleted.

My test code is like this

@Autowired(required=true)
private VetsRepository vetsRepository;
@RequestMapping("/delete/vet")
public ModelAndView createVetHandler(@RequestParam Long vetId) {
vetsRepository.delete(vetId);
ModelAndView mav = new ModelAndView("/vets");
mav.addObject(new VetsList(Lists.newArrayList(vetsRepository.findAll ())));
return mav;
}
The following code will work without deleting the reference in vet_specialties table
Vets vet = vetsRepository.findOne(vetId);
vet.setSpecialties(null);
vetsRepository.delete(vet);

So the problem is when a vets record has a list of spcialties. Then also order records in vets table with the same spcialties will be deleted.
I hope the describtion is clear and it will help you to discover the bug. Either if it is a bug or not, please give some guide lines how to delete a record when it belongs to a ManyToMany relationship.
Thanks