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

后端 未结 5 507
醉梦人生
醉梦人生 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条回答
  •  -上瘾入骨i
    2020-12-08 18:56

    Hibernate uses set method to initialize the entity which you're reading from your DB.

    Maybe, if you make access modifiers of entity fields default or protected or public then Hibernate will initialize fields directly without using setter (I read something about it but I'm not sure that it works). But using setter is much more preferred way.

提交回复
热议问题