This is my Class
@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Email
@NotEmpty
private String email;
@NotEmpty
private String password;
@Transient
@NotEmpty
private String passwordConfirmation;
//constructors, getters, setters omitted....
}
As you can see, the passwordConfirmation is Transient and will not exist on the equivalent table.
I have a UserRepository that save and retrieve User from the database.
public interface UserRepository extends JpaRepository<MyUser, Long> {}
when I save a user
User user1 = new User("zak@gmail.com", "pass", "pass");
userRepository.save(user1);
Everything works fine, but when I retrieve the User for some processing I'm getting a javax.validation.ConstraintViolationException: Validation failed for classes
User user1 = userRepository.findByUsername("zak@gmail.com");
//some procesing
userRepository.save(user1);
When I retrieve the User, the passwordConfirmation get a null value, and for that reason I'm getting this exception.
What could be a good solution for my scenario. Should I reset the passwordConfirmation value.