@RestController
public class MainController {
@GetMapping("/")
public String main() {
return "Main";
}
@GetMapping("/login")
public String login() {return "Login";}
@GetMapping("/after_login")
public String logout() {return "Logout";}
}
User
@ManyToMany(fetch = FetchType.EAGER)
private Set<Role> roles;
Role
@Transient
@ManyToMany(mappedBy = "roles")
private Set<User> users;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
2021-11-11 01:10:51.121 ERROR 15507 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [users_id]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement] with root cause
org.postgresql.util.PSQLException: ERROR: null value in column "users_id" violates not-null constraint
Подробности: Failing row contains (null, 1, 1).
public boolean saveUser(UserDto userDto) {
// User user = userRepository.findByUsername(userDto.getUsername());
// if (user != null) {
// return false;
// }
User user = new User();
user.setRoles(Collections.singleton(new Role(1L, "ROLE_USER")));
user.setUsername(userDto.getUsername());
user.setPassword(bCryptPasswordEncoder.encode(userDto.getPassword()));
userRepository.save(user);
return true;
}
Получается вопрос к ide