Unable to retrieve multiple entities using camel and openjpa

375 Views Asked by At

I am using spark-rest component and want to use a JPA endpoint to fetch multiple entities from an oracle DB using Camel-jpa and openJpa. I've read chapter 6.5 from Camel in Action 2 but only managed to get one single entity at a time, by its Id. However I'm having a lot of trouble when trying to use jpa for retrieving multiple entities, ending up with an openJpa exception, independently of doing a select with or without parameters.

Here is my route:

public class MyRouteBuilder extends RouteBuilder {

    @Override
    public void configure() throws Exception {

            restConfiguration()
              .component("spark-rest")
                .host("localhost").port(8087).bindingMode(RestBindingMode.json);

            rest("/")
              .get("foo/{name}")
              .route()
                .bean(MyService.class.getName(), "myMethod")
                .to("jpa:" + Foo.class.getName() + "?consumer.namedQuery=Foo.findByName&consumeDelete=false")

And the @Entity annotated class is like follows:

@Entity
@Table(name=Foo.TABLE_NAME)
@NamedQueries({
    @NamedQuery(name="Foo.findAll", query="SELECT f FROM Foo f"), 
    @NamedQuery(name="Foo.findByName", query="SELECT f FROM Foo f WHERE f.nombre = :nombre"),
    @NamedQuery(name="Foo.findById", query="SELECT f FROM Foo f WHERE f.persfisica = 1")
})
public class Foo implements Serializable{
    ...
}

The exception returned when sending a GET request to the endpoing defined above is this one:

<openjpa-2.1.0-r422266:1071316 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: This configuration disallows runtime optimization, but the following listed types were not enhanced at build time or at class load time with a javaagent: "
my.package.Foo".
    at org.apache.openjpa.enhance.ManagedClassSubclasser.prepareUnenhancedClasses(ManagedClassSubclasser.java:116)
    at org.apache.openjpa.kernel.AbstractBrokerFactory.loadPersistentTypes(AbstractBrokerFactory.java:315)
    at org.apache.openjpa.kernel.AbstractBrokerFactory.initializeBroker(AbstractBrokerFactory.java:239)
    at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:213)
    at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:156)
    at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:227)
    at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:154)
    at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:60)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.invokeProxyMethod(AbstractEntityManagerFactoryBean.java:388)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean$ManagedEntityManagerFactoryInvocationHandler.invoke(AbstractEntityManagerFactoryBean.java:541)
    at com.sun.proxy.$Proxy17.createEntityManager(Unknown Source)
    at org.apache.camel.component.jpa.JpaHelper.getTargetEntityManager(JpaHelper.java:63)
    at org.apache.camel.component.jpa.JpaProducer.process(JpaProducer.java:57)
    at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
    at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:145)
    at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
    at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:468)
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196)
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:121)
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196)
    at org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:62)
    at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:145)
    at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
    at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:468)
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196)
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:121)
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196)
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:109)
    at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:91)
    at org.apache.camel.component.sparkrest.CamelSparkRoute.handle(CamelSparkRoute.java:46)
    at spark.RouteImpl$1.handle(RouteImpl.java:58)
    at spark.webserver.MatcherFilter.doFilter(MatcherFilter.java:162)
    at spark.webserver.JettyHandler.doHandle(JettyHandler.java:61)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:189)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
    at org.eclipse.jetty.server.Server.handle(Server.java:499)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
    at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
    at java.lang.Thread.run(Thread.java:748)

Similar stacktrace is what I get when trying to get these entities using unit tests.

According to this failed jpa test, it looks like a bug in OpenJpa, but haven't figured out a workaround using jpa component.

Any suggestions?

Just as a side note: This has been tested locally but is to be OSGI compatible, that's the main reason I'm not diving into Spring jpa.

0

There are 0 best solutions below