Forum Home » Fuse Distributions » Fuse Mediation Router

Thread: Persisting a list of entities using jpa endpoint

 

Permlink Replies: 2 - Last Post: Nov 28, 2011 10:11 PM Last Post By: mohithanda
mohithanda

Posts: 13
Registered: 11/28/11
Persisting a list of entities using jpa endpoint
Posted: Nov 28, 2011 2:24 AM
  Click to reply to this thread Reply

Hi Guys,

I am trying to persist a list of entities using a camel route.

So some thing like

exchange.getIn().setBody(BeanToEntityConverter.convertPlanToPlanEntity(plans)); // BeanToEntityConverter.convertPlanToPlanEntity(plans) returns a list of PlanEntity

And following is my route endpoint

.to("jpa:org.myproject.servicebus.services.PlanEntity");

I get the following exception in my logs

at java.lang.Thread.run(Thread.java:662)
Caused by: org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: java.util.ArrayList to the required type: org.myproject.servicebus.services.PlanEntity with value [org.myproject.servicebus.services.PlanEntity@3346e3, mailto:org.myproject.servicebus.services.PlanEntity@72e235, mailto:org.myproject.servicebus.services.PlanEntity@61414d, mailto:org.myproject.servicebus.services.PlanEntity@10637dd, mailto:org.myproject.servicebus.services.PlanEntity@13d9e14, mailto:org.myproject.servicebus.services.PlanEntity@555cb7]

Which actually makes sense to me. But I am really not sure how I could define a jpa endpoint that can persist a list of entities. If I set the exchange body to be a single object i.e. a PlanEntity Object, it works fine.

Any suggestions? Please advise.

Regards,
Mohit
davsclaus

Posts: 1,893
Registered: 10/14/08
Re: Persisting a list of entities using jpa endpoint
Posted: Nov 28, 2011 6:55 AM   in response to: mohithanda in response to: mohithanda
  Click to reply to this thread Reply
You can split the message, and have each splitted message (which would be a single entity) send to the JPA endpoint.
http://fusesource.com/docs/router/2.8/eip/MsgRout-Splitter.html
mohithanda

Posts: 13
Registered: 11/28/11
Re: Persisting a list of entities using jpa endpoint
Posted: Nov 28, 2011 10:11 PM   in response to: davsclaus in response to: davsclaus
  Click to reply to this thread Reply
Thanks Claus.

That's what I did. It works well.

Regards,
Mohit