File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 17260
    
    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