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 annotation on the property or access method? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "annotation on the property or access method? " Watch "annotation on the property or access method? " New topic
Author

annotation on the property or access method?

Alessandro Ilardo
Ranch Hand

Joined: Dec 23, 2005
Posts: 218
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


trying to decode a woman mind....
Shailesh Kini
Ranch Hand

Joined: Oct 17, 2001
Posts: 153
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.


Shailesh Kini.
 
 
subject: annotation on the property or access method?
 
Threads others viewed
AccessMode in JPA 2
is field or property based annotation same
No getter method in inheritance classes
@Embedded annotation for properties.
Annotations on instance declaration or get method using JPA in entities?
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com