This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Field Based Persistence Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Field Based Persistence" Watch "Field Based Persistence" New topic
Author

Field Based Persistence

nitin pai
Ranch Hand

Joined: May 30, 2006
Posts: 185
Does field based persistence mean having annotated public entity variables without getters and setters?

I tried making annotated private entity instance variables and providing getters /setters. It works this way too. So I am now not sure what exactly is meant by field based persistence?



Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1282

Hi nitin,

as you probably now that @Id annotation decides whether to use field or getter/setter based persistence management. If you use field based the members don't have to be public as the entity manager also has access to inject member values even if they are declared private.

I'd personally recommend using the getter/setter based approach though because this allows you to be more flexible if you want to do some additional things in your getter/setter which wouldn't be possible with direct field access.

Marco
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Field Based Persistence