при получении поля из БД возвращается null
Я хочу добавить аватарку профиля, для этого я добавил поле image_filename. При post-методе, когда я выполняю save(), поле сохраняется и в базе данных отображается то, что нужно, но когда я выполняю getImageFilename(), то получаю null, в чем может быть проблема?
post-method:
@PostMapping("changeAvatar")
public String changeAvatar(@AuthenticationPrincipal User user,
@RequestParam("file") MultipartFile file) throws IOException {
File previousAvatar = new File(uploadPath + "/profile-images/" + user.getImageFilename());
previousAvatar.delete();
if (file != null && !Objects.requireNonNull(file.getOriginalFilename()).isEmpty()){
File uploadDir = new File(uploadPath + "/profile-images");
if (!uploadDir.exists()){
uploadDir.mkdir();
}
String fileName = UUID.randomUUID() + "." + file.getOriginalFilename();
file.transferTo(new File(uploadPath + "/profile-images/" + fileName));
user.setImageFilename(fileName);
userRepository.save(user);
}
**System.out.println(user.getImageFilename());**
return "redirect:/profile";
}
User
@Entity
@Table(name = "sweater_user")
public class User implements UserDetails{
private final static long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotBlank(message = "Username should not be empty")
private String username;
@NotBlank(message = "Password should not be empty")
private String password;
@Email(message = "Email is not correct")
@NotBlank(message = "Email should not be empty")
private String email;
private String activationCode;
private boolean active;
private String imageFilename;
public User(String username, String password, String email, String activationCode, boolean active, Collection<Role> roles, String imageFilename) {
this.username = username;
this.password = password;
this.email = email;
this.activationCode = activationCode;
this.active = active;
this.roles = roles;
this.imageFilename = imageFilename;
}
public User() {
}
...
Проблема конкретно с полем imageFilename
После выполнения save()
После System.out.println()

