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

后端 未结 25 1529
说谎
说谎 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:35

    I tend to prefer and to use property accessors:

    • I can add logic if the need arises (as mentioned in the accepted answer).
    • it allows me to call foo.getId() without initializing a proxy (important when using Hibernate, until HHH-3718 get resolved).

    Drawback:

    • it makes the code less readable, you have for example to browse a whole class to see if there are @Transient around there.

提交回复
热议问题