Hibernate Annotations - Which is better, field or property access?

后端 未结 25 1612
说谎
说谎 2020-11-22 15:02

This question is somewhat related to Hibernate Annotation Placement Question.

But I want to know which is better? Access via properties or access vi

25条回答
  •  无人共我
    2020-11-22 15:29

    I prefer fields, but I've run into one situation that seems to force me to place the annotations on getters.

    With the Hibernate JPA implementation, @Embedded doesn't seem to work on fields. So that has to go on the getter. And once you put that on the getter, then the various @Column annotations have to go on the getters too. (I think Hibernate doesn't want mixing fields and getters here.) And once you're putting @Column on getters in one class, it probably makes sense to do that throughout.

提交回复
热议问题