I\'m using Spring with JPA. I have @EnableAsync
and @EnableTransactionManagement
turned on. In my user registration service method, I have a few other
Make a try by creating a new UserService class to manage user check, like so
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public User createOrUpdateUser(User newUser) {
String username = newUser.getUsername();
String email = newUser.getEmail();
// ... Verify the user doesn't already exist
// I have tried all manner of flushing and committing right here, nothing works
newUser = userDAO.merge(newUser);
return newUser;
}
then in the actual class, change
private User registerUser(User newUser, Boolean waitForAccount) {
String username = newUser.getUsername();
String email = newUser.getEmail();
// ... Verify the user doesn't already exist
// I have tried all manner of flushing and committing right here, nothing works
newUser = userDAO.merge(newUser);
by
private User registerUser(User newUser, Boolean waitForAccount) {
newUser = userService.createOrUpdateUser(newUser);
The new userService with @Transactional REQUIRES_NEW should force the commit and solve the issue.