java - spring-data Jpa does not need to execute the save statement, but the Set field can automatically execute the save method? Solve
仅有的幸福
仅有的幸福 2017-06-30 09:55:20
0
3
1450
public Optional<User> requestPasswordReset(String mail) {
    return userRepository.findOneByEmail(mail)
        .filter(User::getActivated) 
        .map(user -> {// updata
            user.setResetKey(RandomUtil.generateResetKey());
            user.setResetDate(Instant.now()); 
            return user;
        });
    
}

//Enter the breakpoint, check the print results through the backend, and find that the select statement is executed first, and then the update statement is executed. I don’t quite understand why after set
//You can update without the save method

After following the code, when I get to this method, I execute the update statement. I ask the master to see it and teach me. I am very grateful! I will definitely pay attention to you.

仅有的幸福
仅有的幸福

reply all(3)
phpcn_u1582

Judging from your screenshot, I didn’t see where the update statement was executed. According to my experience, it will be updated only when the save method is called

女神的闺蜜爱上我

It should be that JPA discovered that your object is dirty and automatically executed it before Transaction commit.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template