EclipseLink添加转换器会间歇性地导致ValidationException

Pau*_*eau 9 eclipse jpa eclipselink

我是第一次使用EclipseLink构建一个新的应用程序.

一切都没问题,直到我添加了一个使用JSR310 Instant作为时间戳列的实体.

所以我创建了一个转换器类并将其映射到相关字段,如下所示:

@Convert(converter = JSR310InstantTypeConverter.class)
private Instant   pwdChangeCodeExpiresOn = null;
Run Code Online (Sandbox Code Playgroud)

但是,由于我添加了转换器,应用程序已开始抛出以下异常:

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)
Run Code Online (Sandbox Code Playgroud)

这将在代码更改后开始发生(当Eclipse重新启动服务器时).我必须手动停止并启动(和/或重新启动)服务器几次,直到它最终再次开始工作.然后它将正常工作,直到代码更改或两个以后它将再次开始抛出异常.

这是一个巨大的痛苦.任何人都知道原因以及如何解决它?

Pau*_*eau 14

好的解决方案找到了.将转换器类添加到persistence.xml文件(如错误消息所示)似乎已解决了该问题.

<persistence-unit name="example" transaction-type="RESOURCE_LOCAL">
  ....
  <class>com.example.utils.JSR310InstantTypeConverter</class>
  ...
</persistence-unit>
Run Code Online (Sandbox Code Playgroud)

我应该早点尝试过.在没有这个的情况下,有些时候工作的事实让我觉得它不会有所作为.

  • 似乎我们在阅读错误消息之前去了Google ...我做了同样的事情.在我们的辩护中,异常呕吐很长. (2认同)