This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes field or property based access Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "field or property based access" Watch "field or property based access" New topic
Author

field or property based access

Peter Curila
Greenhorn

Joined: Oct 11, 2005
Posts: 20
What are pros and cons of using field or property based access in JPA entities? Which one is recommended?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

You basically mean the difference between mapping to the class attribute or a getter/setter

The main difference is if you need some extra code to run before you set or get the value, some extra validation if you need it to go above and beyond Hibernate's built in validation on fields.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Peter Curila
Greenhorn

Joined: Oct 11, 2005
Posts: 20
Thank you Mark,

I am about to start new project with EJB3 and I am new to that.
I am asking because many people choose property based access because of better encapsulation.

But I have an idea to make my entities with private fields so only entity manager can access them. Then write only necessary getters and setters for clients and business logic like validation store in entity listeners.

Peter
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: field or property based access
 
Similar Threads
Annotations on instance declaration or get method using JPA in entities?
The difference between field-based access and property-based access
Mapping annotations for variables.
field or property based access
different betwenn property based and field based persistance