I have been developing blog application using Spring MVC + Spring Data JPA + Hibernate. Now I have a problem with optimistic locking mechanism. I will share a piece of code below. I have added @Version annotation to entity. Than I am using two different browser to update same record at same time. Every time I perform the save action it increases the versioon +1 and updates data. But doesnt throw any exception As you know , expected exception is like OptirmisticException. I have searched but no information about it yet. If you could clarify me, I will be appricate. Here is a piece of code from controller. Thanks All.
@RequestMapping(value="/edit/{id}", method = RequestMethod.POST)
public String postEdit(@PathVariable Long id , @ModelAttribute("category")Category formCategory){
try {
Category category = categoryService.findOneCategory(id);
if(category!=null) {
category.setCatName(formCategory.getCatName());
categoryService.save(category);
}
} catch (Exception e) {
LOGGER.debug("Error message : "+e);
}
return PAGE_DEFAULT;
}