Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Using JPA-RS in Equinox (via gemini)(JPA-RS in OSGi (via gemini) - problems with classloading)
Using JPA-RS in Equinox (via gemini) [message #1709246] Fri, 25 September 2015 08:42 Go to next message
Marco Descher is currently offline Marco DescherFriend
Messages: 197
Registered: October 2010
Location: Austria
Senior Member
Hy there,

I managed to create an equinox based applicatoin, that uses gemini to provide PersistenceUnits. I also managed to provide Entities within this PU according to the tutorial in https://wiki.eclipse.org/EclipseLink/Examples/REST/GettingStarted/RestService.

The problem however is, that according to this solution I have to code the entire REST interface myself - thus I found JPA-RS.

Unfortunately I do not seem to manage to get it running in Equinox. I already have a product that starts my equinox env, and jetty is already there as I use REST in other parts.

What have I done so far? I added org.eclipse.persistence.jpars and its dependencies to my run-configuration and started the bundle in my container. Yet I can't access the url. I also failed in finding a tutorial to employ JPA-RS in Euqinox (there is for glassfish etc.). What have I done wrong? Do I need to start by means of an JPARSApplication ??

Thanks a lot!

[Updated on: Tue, 29 September 2015 13:41]

Report message to a moderator

Re: Using JPA-RS in an Equinox application [message #1709378 is a reply to message #1709246] Mon, 28 September 2015 06:46 Go to previous messageGo to next message
Marco Descher is currently offline Marco DescherFriend
Messages: 197
Registered: October 2010
Location: Austria
Senior Member
My progress here:

The main ws application that should start the code is located in org.eclipse.persistence.jpars.jar called JPARSApplication. I have not found a way, however, to correctly use this in OSGI/Jetty. So I reverted to directly use the REST provider classes by means of OSGI-DS (e.g. registering org.eclipse.persistence.jpa.rs.resources.EntityResource in the bundle org.eclipse.persistence.dbws.jar). This works up until the point when the resp. code tries to get the PersistenceContextFactory (in org.eclipse.persistence.jpa.rs.resources.common.AbstractResource) - which it tries by employing ServiceLoader.load.

ServiceLoader load is not OSGIfied (see e.g. http://coderthoughts.blogspot.co.at/2011/08/javautilserviceloader-in-osgi.html) - so is JPA-RS ready at all to be used in an OSGI environment? It does not seem to be so, as to even run the EclipseLink base in OSGI i have to use Gemini JPA. Does anybody know of an example where JPA-RS was successfully run in an OSGI environment?? thanks
Re: Using JPA-RS in an Equinox application [message #1709552 is a reply to message #1709378] Tue, 29 September 2015 09:08 Go to previous messageGo to next message
Marco Descher is currently offline Marco DescherFriend
Messages: 197
Registered: October 2010
Location: Austria
Senior Member
I got another step further, I pushed the dbws jar into my own plugin and realized an OSGI implementation of the ServiceLoader to overwrite the loading of the EntityManager. This seems to have worked out, after adding moxy (which is required), however, I face this problem:

Caused by: java.lang.ClassCastException: org.eclipse.persistence.jaxb.javamodel.oxm.OXMJavaClassImpl cannot be cast to org.eclipse.persistence.jaxb.javamodel.reflection.JavaClassImpl
	at org.eclipse.persistence.jaxb.javamodel.reflection.JavaClassImpl.getAnnotation(JavaClassImpl.java:122) ~[na:na]
	at org.eclipse.persistence.jaxb.javamodel.Helper.isAnnotationPresent(Helper.java:291) ~[na:na]
	at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.processXmlElementNillable(AnnotationsProcessor.java:655) ~[na:na]
	at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.preBuildTypeInfo(AnnotationsProcessor.java:569) ~[na:na]
	at org.eclipse.persistence.jaxb.compiler.XMLProcessor.processXML(XMLProcessor.java:202) ~[na:na]
	at org.eclipse.persistence.jaxb.compiler.Generator.<init>(Generator.java:106) ~[na:na]
	at org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext$MetadataContextInput.createContextState(DynamicJAXBContext.java:236) ~[na:na]
	at org.eclipse.persistence.jaxb.JAXBContext.<init>(JAXBContext.java:189) ~[na:na]
	at org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext.<init>(DynamicJAXBContext.java:71) ~[na:na]
	at org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContextFactory.createContextFromOXM(DynamicJAXBContextFactory.java:347) ~[na:na]
	at org.eclipse.persistence.jpa.rs.PersistenceContext.createDynamicJAXBContext(PersistenceContext.java:310) ~[na:na]
	at org.eclipse.persistence.jpa.rs.PersistenceContext.init(PersistenceContext.java:206) ~[na:na]
	at org.eclipse.persistence.jpa.rs.PersistenceContext.<init>(PersistenceContext.java:190) ~[na:na]
	at org.eclipse.persistence.jpa.rs.PersistenceFactoryBase.bootstrapPersistenceContext(PersistenceFactoryBase.java:57) ~[na:na]
	at info.elexis.server.core.connector.elexis.jpa.jpars.OSGIPersistenceFactoryBase.get(OSGIPersistenceFactoryBase.java:23) ~[na:na]
	at org.eclipse.persistence.jpa.rs.resources.common.AbstractResource.getPersistenceContext(AbstractResource.java:187) ~[na:na]
	at org.eclipse.persistence.jpa.rs.resources.MetadataResource.buildMetadataCatalogResponse(MetadataResource.java:149) ~[na:na]
	at org.eclipse.persistence.jpa.rs.resources.MetadataResource.getMetadataCatalog(MetadataResource.java:93) ~[na:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_60]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_60]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_60]
	at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_60]
	at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81) ~[na:na]
	at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:144) ~[na:na]
	at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161) ~[na:na]
	at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:160) ~[na:na]
	at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99) ~[na:na]
	at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389) ~[na:na]
	at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347) ~[na:na]
	at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102) ~[na:na]
	at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:308) ~[na:na]
	at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271) ~[na:na]
	at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267) ~[na:na]
	at org.glassfish.jersey.internal.Errors.process(Errors.java:315) ~[na:na]
	at org.glassfish.jersey.internal.Errors.process(Errors.java:297) ~[na:na]
	at org.glassfish.jersey.internal.Errors.process(Errors.java:267) ~[na:na]
	at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317) ~[na:na]
	at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:291) ~[na:na]
	at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1140) ~[na:na]
	at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:403) ~[na:na]
	... 30 common frames omitted


which happens in moxy

org.eclipse.persistence.jaxb.javamodel.reflection.JavaClassImpl

 /**
     * Assumes JavaType is a JavaClassImpl instance
     */
    public JavaAnnotation getAnnotation(JavaClass arg0) {
        // the only annotation we will return if isMetadataComplete == true is XmlRegistry
        if (arg0 != null && (!isMetadataComplete || arg0.getQualifiedName().equals(XML_REGISTRY_CLASS_NAME))) {
            Class annotationClass = ((JavaClassImpl) arg0).getJavaClass();
            if (javaModelImpl.getAnnotationHelper().isAnnotationPresent(getAnnotatedElement(), annotationClass)) {
                return new JavaAnnotationImpl(this.javaModelImpl.getAnnotationHelper().getAnnotation(getAnnotatedElement(), annotationClass));
            }
        }
        return null;
    }


now this does not really make sense to me! I also found older code resp. bugs like https://bugs.eclipse.org/bugs/attachment.cgi?id=223962&action=diff where OXMJavaModelImpl extended JavaModelImpl and implemented JavaModel, now OXMJavaModelImpl does only implement JavaModel.

Any help on this concrete problem?? THanks!
Re: Using JPA-RS in an Equinox application [message #1709568 is a reply to message #1709552] Tue, 29 September 2015 10:27 Go to previous messageGo to next message
Marco Descher is currently offline Marco DescherFriend
Messages: 197
Registered: October 2010
Location: Austria
Senior Member
Getting this even further, the problem seems to lie in the XMLElementNillable annotation. Every time such an annotation is faced (I don't know where it comes from, as I did not declare it in my Entity) the ClassCastException occurs.

https://dl.dropboxusercontent.com/u/72943400/2015-09-29_1225.png
Re: Using JPA-RS in an Equinox application [message #1709591 is a reply to message #1709568] Tue, 29 September 2015 13:01 Go to previous message
Marco Descher is currently offline Marco DescherFriend
Messages: 197
Registered: October 2010
Location: Austria
Senior Member
Okay, I think I'll stop now ... too hard to get JPA-RS run with GEMINI .. I found out, however, that the problem lies in the classloading. In

org.eclipse.persistence.jaxb.javamodel.oxm.OXMJavaModelImpl

  public JavaClass getClass(Class<?> jClass) {
        if (jClass == null) {
            return null;
        }

        String className = jClass.getCanonicalName();
        JavaClass cachedClass = this.javaModelClasses.get(className);

        if (cachedClass != null) {
            return cachedClass;
        }

        // try actually finding the class, might be concrete
        try {
            if (jClass.isArray()) {
                className = jClass.getName();
            }
            Class<?> realClass = PrivilegedAccessHelper.getClassForName(className, true, classLoader);
            if (realClass != null) {
                JavaModelImpl jm = new JavaModelImpl(classLoader);
                JavaClassImpl jc = new JavaClassImpl(realClass, jm);
                return jc;
            }
        } catch (Exception e) {
        }

        return new OXMJavaClassImpl(jClass.getCanonicalName());
    }


it will always silently fail to load the XMLElementNillable.class which results in the Exception. I think it would be a good thing to not silently swallow the exception but provide at least the most minimal log output.

The chain of classloaders is far too complicated, yet I do not understand why it it fails to load a class that is co-located to the mentioned class (just in another package).

I would be really glad if someone deeper involved would just give me a very small feedback.
Previous Topic:GebericEntity<T> json when bootstrapping JAXBXContext
Next Topic:javax.persistence.sql-load-script-source property is not effective
Goto Forum:
  


Current Time: Fri Apr 19 02:26:16 GMT 2024

Powered by FUDForum. Page generated in 0.02312 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top