I have written a custom classloader to be able to dynamically load domain models for each step of an update process. In each step of the update a new thread is created to insure that not only the contextClassloader but the current classloader is also pointing to my own ClassLoader.
This sounds a bit complicated, but it works well.
The latest domain model is added to the project as a static dependency and all previous domain models are added as jar to a resource folder. The custom classloader loads the domain classes from these jar files.
All the domain classes and the eclipselink classes are loaded by my classloader. However I still get the following exception and I do not really understand, why?
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)])
The domain classes are loaded by my classloader and do not have the missing hospitalization field. That is okay, it is how it was supposed to work but somehow eclipselink loads the incorrect domain version statically linked to the project and loads the field names from that.
I have started digging through the eclipselink code but especially this mapping part is not really straightforward.