@Override @Transactional( propagation = Propagation.REQUIRED, readOnly = false) @CachePut( value = "greetings", key = "#greeting.id") public Greeting update(Greeting greeting) { logger.info("> update id:{}", greeting.getId()); counterService.increment("method.invoked.greetingServiceBean.update"); // Ensure the entity object to be updated exists in the repository to // prevent the default behavior of save() which will persist a new // entity if the entity matching the id does not exist Greeting greetingToUpdate = findOne(greeting.getId()); if (greetingToUpdate == null) { // Cannot update Greeting that hasn't been persisted logger.error( "Attempted to update a Greeting, but the entity does not exist."); throw new NoResultException("Requested entity not found."); } greetingToUpdate.setText(greeting.getText()); Greeting updatedGreeting = greetingRepository.save(greetingToUpdate); logger.info("< update id:{}", greeting.getId()); return updatedGreeting; }
@Override @Transactional( propagation = Propagation.REQUIRED, readOnly = false) @CachePut( value = "greetings", key = "#greeting.id") public Greeting update(Greeting greeting) { logger.info("> update id:{}", greeting.getId()); counterService.increment("method.invoked.greetingServiceBean.update"); // Ensure the entity object to be updated exists in the repository to // prevent the default behavior of save() which will persist a new // entity if the entity matching the id does not exist Greeting greetingToUpdate = findOne(greeting.getId()); if (greetingToUpdate == null) { // Cannot update Greeting that hasn't been persisted logger.error( "Attempted to update a Greeting, but the entity does not exist."); throw new NoResultException("Requested entity not found."); } greetingToUpdate.setText(greeting.getText()); Greeting updatedGreeting = greetingRepository.save(greetingToUpdate); logger.info("< update id:{}", greeting.getId()); return updatedGreeting; }