| ClassLoader problem using JPA with Native Eclipselink project file [message #1003363] |
Sun, 20 January 2013 22:30 |
Roger Spall Messages: 3 Registered: January 2013 |
Junior Member |
|
|
Following various helpful documentation, I am trying to use JPA with a Native Eclipse Project. I setup my persistence.xml to point to my Sessions.xml, and meanwhile my Sessions.xml file references a project java file - generated from the Mapping Workbench.
I am testing my application with WebSphere 8 and there is only one copy of eclipselink.jar file (V2.4.1) in the lib directory of my EAR file / application. The eclipselink.jar is in turn referenced from the Manifest.mf file for my EJB project. Anyway, when I start my Enterprise Application, I get a Class cast exception:
com.yamaha.progress.database.connections.ProgressProject incompatible with org.eclipse.persistence.sessions.Project
Given that my ProgressProject was generated from the Mapping Workbench, and that it directly subclasses org.eclipse.persistence.sessions.Project, the problem must be with class loaders. So... I used the WebSphere debugger and located the problem code inside org.eclipse.persistence.internal.sessions.factories.SessionsFactory:
....
if (projectConfig.isProjectClassConfig()) {
try {
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
project = (Project) AccessController.doPrivileged(new PrivilegedNewInstanceFromClass(m_classLoader.loadClass(projectString)));
}else{
project = (Project) PrivilegedAccessHelper.newInstanceFromClass(m_classLoader.loadClass(projectString));
}
} catch (Throwable exception) {
throw SessionLoaderException.failedToLoadProjectClass(projectString, exception);
}
....
During initialization, Eclipselink hits the second project = assignment and throws the exception. Under closer examination, m_classLoader is identified as 'com.ibm.ws.classloader.CompoundClassLoader@9ab7dd4[jpatemp:app:YMUSWebApplications]' and has a different java id to the SessionFactory instance's class loader. This SessionFactory Class Loader (derived from evaluating this.getClass().getClassLoader()) is identified as com.ibm.ws.classloader.CompoundClassLoader@95b78cf[app:YMUSWebApplications]. In both cases the actual class path is identical, but clearly they are different class loaders.
Just to be sure, when I place the eclipselink.jar file in the WebSphere Application Server classpath (not a good idea for a prroduction deployment:-)), the problem goes away, and my mappings work just fine.
I am using the default WebSphere class loading policy(s), namely One class loader per enterprise app and delegation to PARENT_FIRST.
What am I doing wrong? Is there some additional configuration property that I need to set for eclipselink, OR for WebSphere?
|
|
|