Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

annotation on the property or access method?

 
Alessandro Ilardo
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
I'm still having some doubt on where to place the annotation in an entity's property.

My IDE (NetBeans 6), automatically add the annotations just above the property, while many tutorials out there annotate the relative getter.

Is there any particular case when we should annotate the property instead of its getter method?

Thanks in advance
 
Shailesh Kini
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alessandro,

You can either use annotations either on the field level or property (access method) never both. JPA does not like a hybrid approach.
Technical articles on the sun site quotes.
"In the Java Persistence API, an entity can have field-based or property-based access. In field-based access, the persistence provider accesses the state of the entity directly through its instance variables. In property-based access, the persistence provider uses JavaBeans-style get/set accessor methods to access the entity's persistent properties."

You can read more about JPA at JPA

Personally I prefer to use annotations at the field level.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic