🔥 Burn Fat Fast. Discover How! 💪

You don't need to call save on @Transcational method #hibernat | Java Tech News

You don't need to call save on @Transcational method
#hibernate #spring #jpa
When you retrieve an entity from the persistence context (e.g. EntityManager.find() or CrudRepository.findById()), it is automatically marked as managed by the persistence provider (e.g. Hibernate). From the JPA standpoint every modification to the managed entity should be reflected in the underlying DataSource with one remark: any changes to persistent state will be persisted when the Session is flushed. Also we know that @Transactional commits all the changed all together after successful completion, and flushing is always happening as a part of committing. Hence, every successful transaction updates managed entity in the database regardless of CrudRepository.save() or EntityManager.merge() invocations.
https://stackoverflow.com/questions/46708063/springboot-jpa-need-no-save-on-transactional#