Java9中使用jpa,jpa – eclipselink在Java 9上使用final字段进行静态编织
我有一些JPA注釋字段,如下所示:
@Column(name = "SOME_FIELD", updatable = false, nullable = false)
private final String someField;
當(dāng)實體插入數(shù)據(jù)庫時??,這些字段存儲在數(shù)據(jù)庫中.它們無法進(jìn)一步更新.對于Java編程語言,可以將這些字段視為final.
使用EclipseLink靜態(tài)編織插件,由于某些字節(jié)代碼檢測,可能會延遲加載實體.
我不知道JPA中是否正式允許這樣的構(gòu)造(最終字段),但我喜歡使用它們,因為它們在編譯時強(qiáng)制執(zhí)行這些字段并不是要更新.
在Java 8中,使用這種結(jié)構(gòu)構(gòu)建的程序運行良好.但是在Java 9中,當(dāng)涉及EclipseLink靜態(tài)編織時,我得到以下運行時異常:
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
這樣的錯誤似乎是由于以下JVM規(guī)范:
Otherwise, if the field is final, it must be declared in the current
class, and the instruction must occur in an instance initialization
method () of the current class. Otherwise, an IllegalAccessError
is thrown.
因此,我覺得一些編織工具需要一些更新才能實現(xiàn)這個JVM規(guī)范. EclipseLink靜態(tài)編織工具似乎就是其中之一.
問題:
> JPA中允許使用此處提供的最終字段構(gòu)造嗎?
>是否有一個JDK 9選項來禁止檢查最終字段分配,而不僅僅是在類的實例初始化方法()中(作為臨時解決方法)?
編輯:
根據(jù)JPA規(guī)范,JPA中不允許使用最終字段:
The entity class must not be final. No methods or persistent instance variables of the entity class may be final.
總結(jié)
以上是生活随笔為你收集整理的Java9中使用jpa,jpa – eclipselink在Java 9上使用final字段进行静态编织的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2天后mysql_mysql 学习笔记
- 下一篇: python中的数字类型格式与运算,py