java - Why should anybody put annotations on the getters or setters when using JPA to map the classes? -


subject says all... see no advantage of people declaring annotations on getters and/or setters far. me has disadvantage of spreading annotations on class, can make class more unreadable.

putting annotations on fields reduces amount of code post when needing help. tiny advantage though. putting annotations on methods serve no purpose me.

putting annotations on methods forces jpa access properties via methods. makes sense when internal state of object differs database schema:

@entity public class employee {     private string firstname;     private string lastname;      @column(name = "emp_name") // due legacy database schema     public string getname() {         return fisrtname + " " + lastname;     }      public void setname(string name) {         ...     }      ... getters , setters firstname , lastname @transient ... } 

in jpa 2.0 can specify access type @ fine-grained level @access:

@entity @access(accesstype.field) public class employee {     @access(accesstype.property) @column(name = "emp_name")     public string getname() { ... }     ... other properties have field access ... } 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -