wood burning stoves 2.0*
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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: 17250
    
    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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: field or property based access