Although there are discussions recommendation is to use the annotation directly in the attribute, just like you’re doing.
The intention of ORM, in the case Hibernate, is to persist the state of the object, thus attributes are the representation of state of the object.
The intention to map an advisory method is questioned by the fact that seldom there is legitimacy in modifying state of an object directly when obtaining it.
For example:
@Column
public String getUnidadeFederativa(){
uf = (uf == null ? "UF não informada" : uf)
return uf;
}
The above block may even make sense for a specific local use, but exceeds the boundaries of the encapsulation of a record originating from a SGBD, in which consistency is mandatory for that context, the above example would not have Constraint in the database with the UF table, ie encapsulation of the information was arbitrarily affected by an advisory method.
So why is it possible to map an advisory method?
There are some specific situations that may be legitimate, it is relative, but one of them is to need to map information into subclasses of Entity Classes third-party (third party) which does not implement any kind of persistence, the attributes of that entity would be private and you would have to overwrite the advisors and then map them with annotations.
(example taken from comment of Elnur Abdurrakhimov in the Stack Overflow US)
Follow the Soen link with your question, http://stackoverflow.com/a/6084701
– Rafael