Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

field or property based access

 
Peter Curila
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are pros and cons of using field or property based access in JPA entities? Which one is recommended?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Peter Curila
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic