I will write a little example code which generates the compiler warning in the header:
@Entity class User {
private String passwordHash;
public User() {}
public User(String passwordHash) {
this.passwordHash = passwordHash;
}
@Column(name="PASSWORD")
public String getPasswordHash() {
return passwordHash;
}
private void setPasswordHash(String passwordHash) {
this.passwordHash = passwordHash;
}
}
I'm currently using hibernate only for filling the database, but later on I will only use it for reading most of the time.
I cannot change it to private final passwordHash
because then I would have to initialize it in the default Constructor.
My Question now is, what could happen if I ignore the warning, or how can I get rid of it without making the the SETTER public or protected? I thought hibernate can get it through reflection even if it is private (Like described here)?
UPDATE:
I tested it with deleting the private
setter. Hibernate is using it via reflection, so the setter has to be there. But since it is a password hash, I cannot change the visibility to public. Protected would be okay, but I would not be happy because in my eyes it isn't a good solution.