我是第一次使用EclipseLink构建一个新的应用程序。
一切正常,直到我添加了一个使用JSR310 Instant作为时间戳列的实体。
因此,我创建了一个转换器类,并将其映射到关联的字段,如下所示:
@Convert(converter = JSR310InstantTypeConverter.class)
private Instant pwdChangeCodeExpiresOn = null;
但是,自从我添加了该转换器以来,该应用程序已开始引发以下异常:
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)
这将在代码更改后开始发生(Eclipse重新启动服务器时)。我必须手动停止并启动(和/或重新启动)服务器几次,直到最终再次开始工作。然后它将正常工作,直到一到两个代码更改之后,它将再次开始引发异常。
这是一个巨大的痛苦。有人知道原因以及如何解决吗?
最佳答案
确定解决方案。根据错误消息的建议,将转换器类添加到persistence.xml文件中,似乎已经解决了该问题。
<persistence-unit name="example" transaction-type="RESOURCE_LOCAL">
....
<class>com.example.utils.JSR310InstantTypeConverter</class>
...
</persistence-unit>
我应该早点尝试一下。有时在没有此功能的情况下工作的事实使我认为这不会有所作为。
关于EclipseLink添加一个Converter会间歇性地导致ValidationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24620323/