The JPA 2.1 specification says:
The entity class must not be final. No methods or persistent instance
variables of the entity class may be final.
Does "no methods" mean *every single* method—private, static, protected,
non-state-changing, etc.—in the entity class? Or was this supposed to
convey that only methods annotated with @Access(AccessType.PROPERTY) are
prohibited from being final?
I understand why entity classes cannot be final, and I understand why
persistent instance variables of the entity class cannot be final. I also
understand why persistent property accessors and mutators cannot be final.
I don't understand why all other methods (ones that manipulate
transientfields, for example, or that are stateless) cannot be
final.
The best I can surmise is that the specification wanted to leave the door
open for bytecode injection everywhere—e.g. perhaps my stateless method's
invocation of a getter needs to have that invocation be rewritten to invoke
some kind of JPA-provider-injected method instead.
This makes it hard to reuse entity-like classes From Elsewhere as building
blocks, since some of them may feature final methods, but are in every
other way suitable for augmenting with an orm.xml and thereby for
transforming into JPA entities.
Any help appreciated. In the meantime, I'll adhere to the letter of the
specification.
Best,
Laird
--
http://about.me/lairdnelson