Friday, 25 January 2008

JPA Mapping Tips

Personally I prefer the annotations on the fields as it makes it easy to locate the annotation and change it.

JPA Tips

Interestingly (or not as the case may be), how the JPA implementation decides whether to look for a annotation on a method or a field is how you annotate the @Id. If the id is annotated on the field, then the JPA implementation expects to find the rest of the annotations on the fields. This is interesting because if you have a class with two attributes and you choose (for some bizarre reason) to put the annotation for field a on the attribute and for field b on the method, then chances are your annotation for field b will be ignored. (Well it will be if you are using Hibernate as your provider at least).

No comments: