Discussions

EJB design: What does the access type in entities mean?

  1. What does the access type in entities mean? (1 messages)

    Hi, What does the access type mean? What matter does it practically make if I annotate fields or getters/setters? I understand that I should avoid mixing these access types, and everything there is to understand about how to configure it, but I just don't understand what it is... I must declare fields as not-private if I'm using field access type? It would be great if someone can explain that even with a piece of code. Thanks, Amit
  2. OK I found the answer. When annotating fields, the persistence provider directly accesses the fields and doesn't invoke the getters/setters as it would do when property accessor annotation is used. Property accessor annotations, on the one hand allows more flexibility in validating just-read data or refining going-to-be-written data, but this will also be called in entity state transitions. Also, you really rarely need validation of just-read data. Use callback methods if you do need it. Obviously, the logical property name will be determined from either the getter/setter, or from the field name. Also, annotating fields and not getters/setters allows decoupling the public getter/setter methods with the underlying type of the columns and the logical properties. Amit Kasher