why the jpa annotations are applied on field or on getter methods. if i try to apply the annotations on setter method then compiler generate the error. because compiler ignore the annotation on setter method. what is the reason behind them?
This is is how it's specified. Per JPA Specification:
- When field-based access is used, the object/relational mapping annotations for the entity class annotate the instance variables, and the persistence provider runtime accesses instance variables directly. All non-transient instance variables that are not annotated with the Transient annotation are persistent.
- When property-based access is used, the object/relational mapping annotations for the entity class annotate the getter property accessors[7], and the persistence provider runtime accesses persistent state via the property accessor methods. All properties not annotated with the Transient annotation are persistent.
- Mapping annotations must not be applied to fields or properties that are transient or Transient.
You have two options. Either use field level annotation or property (getter method) annotation. There is no third option.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With