Sean Barry
Sean Barry

Reputation: 53

Camel JPA - No Persistence provider for EntityManager named camel

I am trying to get the following code to work so I can consume from a JPA entity.

String DATASOURCE_CONTEXT = "java:jboss/datasources/WikiDS"; 

Connection result = null; 
DataSource datasource = null; 

try { 
Context initialContext = new InitialContext(); 
   datasource = (DataSource)initialContext.lookup(DATASOURCE_CONTEXT); 

   if (datasource == null) { 
    System.out.println("Data source is null"); 
   } 
   else { 
    System.out.println("Data source is OK!!!"); 
   } 
} 
catch(NamingException ex) { 
System.out.println("Naming exception is: " + ex.getMessage()); 
} 

SimpleRegistry reg = new SimpleRegistry() ; 
reg.put("myDataSource",datasource); 

CamelContext context = new DefaultCamelContext(reg); 

    ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false"); 
    context.addComponent("test-jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory)); 
    context.addRoutes(new RouteBuilder() { 
        public void configure() { 
            from("jpa://org.apache.camel.example.jmstofile?consumer.namedQuery=step1&consumeDelete=false").to("file://test"); 
        } 
    }); 

    ProducerTemplate template = context.createProducerTemplate(); 
    context.start(); 

Whatever I do I get the following exception.

[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.1.1:java (default-cli) on project camel-example-jms-file: An exception occured while executing the Java class. null: InvocationTargetException: No Persistence provider for EntityManager named camel.

Any ideas how to fix this?

Regards,

Sean

Upvotes: 3

Views: 2103

Answers (1)

Peter Keller
Peter Keller

Reputation: 7636

Add &persistenceUnit=<name-of-your-unit> to your URI, where <name-of-your-unit> is the name of the persistence unit given in persistence.xml.

Upvotes: 4

Related Questions