This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma 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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Field Based Persistence" Watch "Field Based Persistence" New topic

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

Joined: Mar 07, 2007
Posts: 1294

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.

I agree. Here's the link:
subject: Field Based Persistence
jQuery in Action, 3rd edition