我在使用Eclipselink的DescriptorCustomizer for History时收到ClassCastException。
我的自定义程序类如下:
public class MyCustomizer implements DescriptorCustomizer {
@Override
public void customize(ClassDescriptor classDescriptor) thorws Exception {
// Setting HistoryPolicy here.
}
}
该实体注释为:
@Customizer(full.packagename.MyCustomizer.class)
这是在Maven项目的EJB模块中完成的,结构如下:
Eclipslink依赖关系是:
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.6.3</version>
<scope>provided</scope>
</dependency>
代码在WebSphere Liberty 17.0.0.2上运行,没有部署其他应用程序。 Eclipselink jar位于服务器的全局lib目录中。
当Eclipselink首次尝试访问该实体时,我收到以下异常:
MyCustomizer cannot be cast to org.eclipse.persistence.config.DescriptorCustomizer
我试图在应用程序包中包含Eclipselink,但结果是一样的。什么可以阻止正确的铸造,我该如何解决?
编辑#1
我将eclipselink依赖项更改为:
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.core</artifactId>
<version>2.6.3</version>
<scope>provided</scope>
</dependency>
由于它不包含javax.persistence包,因此它不会干扰Websphere的内部。
如果我在应用程序中进行手动转换以进行测试,则不会抛出任何异常。在EntityManager上调用getCriteriaBuilder()时抛出ClassCastException。
答案 0 :(得分:0)
After a few hours of suffering there's a solution for this problem:
The application part was OK.
I had to change the server.xml the following way: for the application's classloader I had to append the apiTypeVisibility="spec, ibm-api, third-party". Since I was using a specified library, I had to append this specifier there too.
So the relevant parts of the server.xml:
<library id="appLibrary" apiTypeVisibility="spec, ibm-api, third-party">
...
</library>
<application id="app_ear" ...>
<classloader commonLibraryRef="appLibrary" apiTypeVisibility="spec, ibm-api, third-parth">
</application>