very stupid question since I’ve been using hibernate for some time now but I was facing a special case and suddenly realised that I’m not sure how hibernate populates the DB entities.
public class User {
...
@Column
private String name;
public void setName(String name) {
this.name = name;
}
}
When hibernate creates a new instance of User (when loading from the DB) how will it populate the property name of that instance? I always assumed hibernate would call setName for this but the case I’m having makes me suspect hibernate ignores the setter and (with reflection) sets the field’s value directly?
thanks,
Stijn
Hibernate annotations and JPA use the placement of the Annotation to determine what kind of access to use. In the example you provided above, it would use field access.
from the Hibernate Annotations documentation: