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

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

    I prefer field access, because that way I'm not forced to provide getter/setter for each property.

    A quick survey via Google suggests that field access is the majority (e.g., http://java.dzone.com/tips/12-feb-jpa-20-why-accesstype).

    I believe field access is the idiom recommended by Spring, but I can't find a reference to back that up.

    There's a related SO question that tried to measure performance and came to the conclusion that there's "no difference".

提交回复
热议问题