Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EclipseLink adding a Converter causes ValidationException intermittently

I am building a new application using EclipseLink for the first time.

Everything was going okay until I added an entity that uses JSR310 Instant for a timestamp column.

So I created a converter class and mapped it to the the associated field like so:

@Convert(converter = JSR310InstantTypeConverter.class)
private Instant   pwdChangeCodeExpiresOn = null;

However since I added that converter the application has started throwing the following exception:

SEVERE: Servlet.service() for servlet [APIJerseyServlet] in context with path [/Sclera] threw exception [org.glassfish.jersey.server.ContainerException: java.lang.ExceptionInInitializerError] with root cause
Local Exception Stack: 
Exception [EclipseLink-7351] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.ValidationException
Exception Description: The converter class [com.sclera.utils.JSR310InstantTypeConverter] specified on the mapping attribute [pwdChangeCodeExpiresOn] from the class [com.sclera.entity.Admin] was not found. Please ensure the converter class name is correct and exists with the persistence unit definition.
    at org.eclipse.persistence.exceptions.ValidationException.converterClassNotFound(ValidationException.java:2317)
    at org.eclipse.persistence.internal.jpa.metadata.converters.ConvertMetadata.process(ConvertMetadata.java:248)

This will start happening after a code change (when Eclipse restarts the server). I have to stop and start (and/or restart) the server manually a few times until it finally starts working again. Then it will work fine until a code change or two later when it will start throwing the exception again.

This is an enormous pain. Anyone know the cause and how to fix it?

like image 744
Paul LeBeau Avatar asked Jul 07 '14 21:07

Paul LeBeau


1 Answers

Okay solution found. Adding the converter class to the persistence.xml file - as suggested by the error message - seems to have resolved the problem.

<persistence-unit name="example" transaction-type="RESOURCE_LOCAL">
  ....
  <class>com.example.utils.JSR310InstantTypeConverter</class>
  ...
</persistence-unit>

I should have tried that earlier. The fact that is working some of the time without this made me think it wouldn't make a difference.

like image 190
Paul LeBeau Avatar answered Sep 23 '22 05:09

Paul LeBeau