【问题标题】:EclipseLink adding a Converter causes ValidationException intermittentlyEclipseLink 添加转换器会间歇性地导致 ValidationException
【发布时间】:2014-08-28 12:14:15
【问题描述】:

我是第一次使用 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 重新启动服务器时)。我必须手动停止和启动(和/或重新启动)服务器几次,直到它最终再次开始工作。然后它会正常工作,直到一两次代码更改后它会再次开始抛出异常。

这是一个巨大的痛苦。有人知道原因和解决方法吗?

【问题讨论】:

    标签: eclipse jpa eclipselink


    【解决方案1】:

    找到好的解决方案。将转换器类添加到persistence.xml 文件中——正如错误消息所建议的——似乎已经解决了问题。

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

    我应该早点尝试的。事实上,如果没有这个,有时它会起作用,这让我认为它不会有什么不同。

    【讨论】:

    • 似乎我们在阅读错误消息之前先去谷歌......我也做了同样的事情。在我们的辩护中,异常呕吐物很长。
    • 还要确保使用@Converter
    猜你喜欢
    • 2015-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-06
    • 2010-10-08
    • 2014-11-07
    • 2023-03-31
    • 1970-01-01
    相关资源
    最近更新 更多