How does Hibernate determine whether an entity needs to be updated?

User user = userService.findById(1L);
// do nothing
user =;

no update sql to run because (user) have nothing change.
I want to know where is the source code that hibernate5 to decide whether need update.

23333…my english is so bad.

When you call save, Spring calls merge so the detached entity state is copied onto a newly fetched one. Then, the dirty checking mechanism detects all the modifications that were done due to copying the detached entity state