aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Field vs Property access for Entities Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Field vs Property access for Entities" Watch "Field vs Property access for Entities" New topic
Author

Field vs Property access for Entities

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9629
    
    2

Guys,

When using a field access for annotating my entities, the getters and setters need not be present. Is this true?


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9629
    
    2

Got this below line from Pro EJB 3,

Annotating the fields of the entity will cause the provider to use field access to get and set the
state of the entity. Getter and setter methods may or may not be present, but if they are present,
they are ignored by the provider


But how will I get and set my values?
Sergio Tridente
Ranch Hand

Joined: Mar 22, 2007
Posts: 329

Originally posted by Jothi Shankar Kumar Sankararaj:
But how will I get and set my values?


Exactly.

Furthermore, it is dictated by the specification. Accordingly to section 2.1 (Requirements on the Entity class):


The persistent state of an entity is represented by instance variables, which may correspond to Java Beans properties. An instance variable may be directly accessed only from within the methods of the entity by the entity instance itself. Instance variables must not be accessed by clients of the entity. The state of the entity is available to clients only through the entity’s accessor methods (getter/setter methods) or other business methods. Instance variables must be private, protected, or package visibility.


SCJP 1.4 (88%) - SCJP 5.0 Upgrade (93%) - SCWCD 1.4 (97%) - SCBCD 5.0 (98%)
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9629
    
    2

Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Field vs Property access for Entities