I have JPA annotated fields declared as:
@Column(name = "SOME_FIELD", updatable = false, nullable = false)
private final String someField;
These fields are stored in the database when an object is inserted into the database. They cannot be updated. For the Java programming language, such fields can be considered final.
Using the EclipseLink static weaving plugin, it allows lazy loading objects due to the use of some byte codes.
I don’t know if such constructions (final fields) are officially allowed in JPA, but I like to use them because they compile in time that these fields are not intended for updating.
In Java 8, programs created with such constructs work fine. But in Java 9, when the EclipseLink static weave is involved, I get the following exception at runtime:
Caused by: java.lang.IllegalAccessError: Update to non-static final field xxx.yyy.SomeEntity.someField attempted from a different method (_persistence_set) than the initializer method <init>
This error is apparently due to the following JVM specification:
Otherwise, if the field is final, it must be declared in the current class, and the instruction must be executed in the initialization of the method () instance of the current class. Otherwise, IllegalAccessError is thrown.
Therefore, I feel that some weaving tools need updating to fulfill this JVM specification. The EclipseLink static weaving tool seems to be one of them.
Questions
- Are final field constructs, such as those presented here, permitted in JPA?
- Is there a JDK 9 option to disable checking the final assignment of a field elsewhere, except in the initialization method of the instance () of the class (as a temporary workaround)?
Edit
End fields are not allowed in JPA, in accordance with JPA specifications:
. .