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

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

    I favor field accessors. The code is much cleaner. All the annotations can be placed in one section of a class and the code is much easier to read.

    I found another problem with property accessors: if you have getXYZ methods on your class that are NOT annotated as being associated with persistent properties, hibernate generates sql to attempt to get those properties, resulting in some very confusing error messages. Two hours wasted. I did not write this code; I have always used field accessors in the past and have never run into this issue.

    Hibernate versions used in this app:

    <!-- hibernate -->
    <hibernate-core.version>3.3.2.GA</hibernate-core.version>
    <hibernate-annotations.version>3.4.0.GA</hibernate-annotations.version>
    <hibernate-commons-annotations.version>3.1.0.GA</hibernate-commons-annotations.version>
    <hibernate-entitymanager.version>3.4.0.GA</hibernate-entitymanager.version>
    
    0 讨论(0)
提交回复
热议问题