【问题标题】:Loading eclipselink domain model with custom classloader under weblogicweblogic下使用自定义类加载器加载eclipselink域模型
【发布时间】:2013-09-05 21:44:34
【问题描述】:

我编写了一个自定义类加载器,以便能够为更新过程的每个步骤动态加载域模型。在更新的每个步骤中,都会创建一个新线程,以确保不仅 contextClassloader,而且当前的类加载器也指向我自己的 ClassLoader。

这听起来有点复杂,但效果很好。

最新的域模型作为静态依赖添加到项目中,所有以前的域模型作为 jar 添加到资源文件夹。自定义类加载器从这些 jar 文件中加载域类。

所有域类和 eclipselink 类都由我的类加载器加载。但是我仍然得到以下异常,我不太明白,为什么?

Exception [EclipseLink-59] (Eclipse Persistence Services - 2.1.3.v20110304-r9073): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The instance variable [hospitalization] is not defined in the domain class [example.role.Patient], or it is not accessible.
Internal Exception: java.lang.NoSuchFieldException: hospitalization
Mapping: org.eclipse.persistence.mappings.DirectToFieldMapping[hospitalization-->Patient.hospitalization]
Descriptor: RelationalDescriptor(example.role.Patient --> [DatabaseTable(Role), DatabaseTable(Patient)])

域类由我的类加载器加载,并且没有缺少的 hospitalization 字段。没关系,它应该是这样工作的,但是 eclipselink 以某种方式加载了静态链接到项目的不正确的域版本,并从中加载了字段名称。

我已经开始深入研究 eclipselink 代码,但尤其是这个映射部分并不是很简单。

【问题讨论】:

    标签: java eclipselink classloader


    【解决方案1】:

    Eclipselink 使用 ASM 直接从类的字节表示中构建元数据。它通过 getResourceAsStream(className) 加载类。我的类加载器已将这些调用委托给父类加载器,这就是为什么总是使用静态链接域的原因。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-20
      • 1970-01-01
      • 1970-01-01
      • 2012-11-08
      • 2013-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多