Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

The difference between field-based access and property-based access

 
Ranch Hand
Posts: 30
Eclipse IDE Spring Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

There is written:

EJB3 in Action wrote:Defining O/R mapping using fields or instance variables of entity is known as field-based access, and using O/R mapping with properties is known as property-based access.



I have some doubts about the following questions:
What do the authors mean under "field-based access" and "property-based access"? What are fields and properties? and what is the difference between them?

Thanks a lot in advance,
Alex.
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Alexey Saenko wrote:
I have some doubts about the following questions:
What do the authors mean under "field-based access" and "property-based access"? What are fields and properties? and what is the difference between them?



Field based access uses the member variables whereas property based access uses getter/setters.
 
Alexey Saenko
Ranch Hand
Posts: 30
Eclipse IDE Spring Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In other words, in terms of practice in the case of field-based access a developer annotates instance variables and in the case of property-based he (or she) annotates getters/setters, right? Is there really so big difference between such styles to annotate? It looks like these styles are completely identical. Am I wrong?
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Alexey Saenko wrote:In other words, in terms of practice in the case of field-based access a developer annotates instance variables and in the case of property-based he (or she) annotates getters/setters, right?


That's correct.

Alexey Saenko wrote:
Is there really so big difference between such styles to annotate? It looks like these styles are completely identical. Am I wrong?



It's more of a personal choice. But the important thing is, you can't mix and match those 2 styles. i.e. your entity should not be annotated at field level as well as property level.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jaikiran Pai wrote:

Alexey Saenko wrote:In other words, in terms of practice in the case of field-based access a developer annotates instance variables and in the case of property-based he (or she) annotates getters/setters, right?


That's not correct.Only getters can be annotated.

JPA specification says,
2.1.1 Persistent Fields and Properties
When property-based access is used, the object/relational mapping annotations for the entity class
annotate the getter property accessors

 
Ranch Hand
Posts: 10192
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's nothing wrong when you annotate the setter, but it will be silently ignored by the container.
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Durai Kalairajan wrote:

Jaikiran Pai wrote:

Alexey Saenko wrote:In other words, in terms of practice in the case of field-based access a developer annotates instance variables and in the case of property-based he (or she) annotates getters/setters, right?


That's not correct.Only getters can be annotated.




Durai, you are right. I did not choose the exact term while explaining that. For property based access, annotating setters will not help.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic