Does Hibernate always need a setter when there is a getter?

后端 未结 5 517
醉梦人生
醉梦人生 2020-12-08 18:01

We have some Hibernate getter methods annotated with both @Column and @Basic.

We get an exception if we don\'t have the corresponding sette

5条回答
  •  眼角桃花
    2020-12-08 18:41

    If you don't use setters and use private attributes, Hibernate would have to retrieve Fields by reflection and do field.setAccessible(true). I don't think Hibernate does that.

    I don't really know if we can tell to Hibernate to do that, but as far as i remember, default config is using setters... Put a log/sysout on a set and you'll see that it uses the setter.

提交回复
热议问题