I have this AppUser entity:
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity
public class AppUser implements UserDetails {
@Id
@SequenceGenerator(
name = "appUser_sequence",
sequenceName = "appUser_sequence",
allocationSize = 1
)
@GeneratedValue(
strategy = GenerationType.SEQUENCE,
generator = "appUser_sequence"
)
private Integer id;
private String firstname;
private String lastname;
private String email;
private String password;
@Lob
private byte[] profileImage;
private Role role;
// rest of the code
When i try to use this method to extract the user in the AppUserService:
@Override
public AppUser loadUserByUsername(String email) throws UsernameNotFoundException {
return repository.searchByEmail(email)
.orElseThrow(()-> new UsernameNotFoundException("Email not found"));
}
I get this error: org.springframework.orm.jpa.JpaSystemException: Unable to extract JDBC value for position 6
The error is refering to profileImage, it said that JPA is unable to extract the byte array from the user, (the user is successfully saved in the database, i just can't extract it from my postgres database)
this is the service that receive a 64 string rappresenting the image and encode it in a byte array:
public AuthenticationResponse register(RegistrationRequest registerRequest) {
byte[] profileImageBytes = null;
if (registerRequest.getProfileImageData() != null)
profileImageBytes = Base64.getDecoder().decode(registerRequest.getProfileImageData());
AppUser appUserToRegister = AppUser.builder()
.firstname(registerRequest.getFirstname())
.lastname(registerRequest.getLastname())
.email(registerRequest.getEmail())
.password(passwordEncoder.encode(registerRequest.getPassword()))
.profileImage(profileImageBytes)
.role(Role.USER)
.build();
appUserService.saveUser(appUserToRegister);
String token = jwtService.generateToken(appUserToRegister);
return new AuthenticationResponse(token);
}