Reputation: 4688
I wanted to react to every change of a field of an EJB Entity Bean. What i did was simply putting some Code into the Setter.
What i expected was some dramatic crash, because the setter would get called on every initialization (maybe even multiple times).
What happened instead that it worked flawlessly, the getter only got called when the value was changed and not upon initialization.
But i wonder why is that? Are the enities initialized via reflection?
Upvotes: 0
Views: 470
Reputation: 691635
It depends on the access type. If all the mapping annotations are put on fields, JPA sets the fields directly, without going through the setters, and reads the state of the entity from the fields directly.
If the mapping annotations are on the getters, JPA uses the setters to populate the entity and the getters to retrieve their state.
The access type can be customized with the Access annotation.
Upvotes: 1