0

I receive a ClassCastException when using Eclipselink's DescriptorCustomizer for History.

My customizer class looks like:

public class MyCustomizer implements DescriptorCustomizer {
    @Override
    public void customize(ClassDescriptor classDescriptor) thorws Exception {
        // Setting HistoryPolicy here.
    }
}

The entity is annotated with:

@Customizer(full.packagename.MyCustomizer.class)

This is done in the EJB module in a Maven project that is structured like:

  • root
    • ear
    • ejb
    • war

The Eclipslink dependency is:

<dependency>
  <groupId>org.eclipse.persistence</groupId>
  <artifactId>eclipselink</artifactId>
  <version>2.6.3</version>
  <scope>provided</scope>
</dependency>

The code is running on WebSphere Liberty 17.0.0.2 on which there are no other applications deployed. The Eclipselink jar is in the server's global lib directory.

When the Eclipselink is first trying to access the entity I receive the following exception:

MyCustomizer cannot be cast to org.eclipse.persistence.config.DescriptorCustomizer

I tried to include the Eclipselink in the application's package but the result is the same. What can prevent the proper casting and how can I fix it?

EDIT #1

I changed the eclipselink dependency to:

<dependency>
  <groupId>org.eclipse.persistence</groupId>
  <artifactId>org.eclipse.persistence.core</artifactId>
  <version>2.6.3</version>
  <scope>provided</scope>
</dependency>

Since it does not contain the javax.persistence package thus it can not interfere with the Websphere's internal.

If I am doing manual casting in the application for testing purposes then there is no exception thrown. The ClassCastException is thrown when the getCriteriaBuilder() is called on the EntityManager.

bdz
  • 270
  • 2
  • 9

1 Answers1

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>
bdz
  • 270
  • 2
  • 9