NPE occurs without @Entity annotation
-------------------------------------
Key: CAMEL-3335
URL: https://issues.apache.org/activemq/browse/CAMEL-3335
Project: Apache Camel
Issue Type: Bug
Components: camel-jpa
Affects Versions: 2.4.0
Reporter: Sergey Zhemzhitsky
Here is code of the org.apache.camel.component.jpa.JpaConsumer class
protected String getEntityName(Class<?> clazz) {
Entity entity = clazz.getAnnotation(Entity.class);
// Check if the property name has been defined for Entity annotation
if (!entity.name().equals("")) { // line 307
return entity.name();
} else {
return null;
}
}
When trying to consume entities from jpa endpoint exception occurs
java.lang.NullPointerException
at
org.apache.camel.component.jpa.JpaConsumer.getEntityName(JpaConsumer.java:307)
at
org.apache.camel.component.jpa.JpaConsumer.createQueryFactory(JpaConsumer.java:287)
at
org.apache.camel.component.jpa.JpaConsumer.getQueryFactory(JpaConsumer.java:196)
at
org.apache.camel.component.jpa.JpaConsumer$1.doInJpa(JpaConsumer.java:83)
at
org.apache.camel.component.jpa.JpaTemplateTransactionStrategy$1$1.doInJpa(JpaTemplateTransactionStrategy.java:82)
at org.springframework.orm.jpa.JpaTemplate.execute(JpaTemplate.java:183)
at org.springframework.orm.jpa.JpaTemplate.execute(JpaTemplate.java:146)
at
org.apache.camel.component.jpa.JpaTemplateTransactionStrategy$1.doInTransaction(JpaTemplateTransactionStrategy.java:80)
at
org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)
at
org.apache.camel.component.jpa.JpaTemplateTransactionStrategy.execute(JpaTemplateTransactionStrategy.java:78)
at org.apache.camel.component.jpa.JpaConsumer.poll(JpaConsumer.java:79)
at
org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:98)
at
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at
java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)
at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:181)
at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:205)
at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
This is because there is no @Entity annotation and persistence is configured by
means of orm.xml.
To fix the problem change line 307 to
if (entity != null && !entity.name().equals(""))
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.