I am trying to code a little reactive backend with R2DBC and run into a thing I do not really understand. I dont know why but Spring is trying to update an entry instead of saving it to the database.
My User Model:
@Table("user")
@NoArgsConstructor
@Data
public class User {
@Id
private String id;
private String username;
private String password;
public User(String id,String username,String password){
this.id = id;
this.username = username;
this.password=password;
}
My Controller:
@RestController
public class UserController {
` private final UserRepository userRepository`;
@Autowired
public UserController(UserRepository userRepository){
this.userRepository = userRepository;
}
@PostMapping("/create")
public Mono<User> createUser(@RequestBody User user){
return userRepository.save(user);
}
When I sent a POST request to this endpoint with input like this for example:
{ "id" : "re", "username" : "ehmmidk", "password" : "dsadsadsadsa" }
it does an update insted of a save even when there is no entries in my database.
My schema looks like this:
CREATE TABLE user (
id VARCHAR(255) NOT NULL ,
username VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL,
PRIMARY KEY (id),
UNIQUE(username)
);