Adam Bien's Weblog
Property Based Access in JPA - is an Emerging Antipattern
Thinking longer about property, vs field based access, I cannot imagine a reasonable use case for the property based annotation. It is much cleaner to hide the internal, also persistent, state and expose only business methods (instead of dumb getters/setters).
So you should use:
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="ID")
private Long id;
instead of:
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="ID")
public Long getId(){return this.id;}
The field-based injection clearly separates between the business logic and state and promotes encapsulation.
And remember, Getters/Setters are evil, but sometimes necessary (e.g. if you like to use detached objects as Value Objects).
Posted at 11:40AM Nov 16, 2006 by Adam Bien in Java EE 5 Architectures And Idioms | Kommentare[4]
[my tweets]
Rss My book: Real World Java EE - Rethinking Best Practices

