You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by erik_romson <er...@zenior.no> on 2015/06/10 09:05:19 UTC

spring boot, jpa, entitymanagers and Java DSL

Hi,
I'm a bit confused regarding the JPA endpoint and entitymanagers.

I'm using spring boot and using the *default* entitymanager. As the
documentation points out, the endpoints use different entity managers

There are documentation of how to set an entity manager using spring xml or
creating a JPA endpoint (new JpaComponent(), set entity Manager etc)

if I have a route

from("jpa://SomeEntity?consumer.namedQuery=query")
.process(ReadSomeOtherStuffWithEntityManager())
.to("jpa://SomeOtherEntity") 


to have the same entityManagerFactory my plan was to use

JpaComponent jpaComponent=new JpaComponent();
//injected entitymanager from spring
jpaComponent.setEntityManagerFactory(entityManager.getEntityManagerFactory());
jpaComponent.setJoinTransaction(false);
jpaComponent.setCamelContext(getContext());
JpaEndpoint jpaEndpointPerson= new
JpaEndpoint(jpa://SomeEntity?consumer.namedQuery=query,jpaComponent);

and add it to the from() in the route and thereafter use the passed along
entity manager.

This doesn't work as as the jpaEndpoint doesn't parse/read the uri (nothing
is set in org.apache.camel.component.jpa.JpaConsumer#createQueryFactory)


I'm probably blind but I fail to find any documentation on how to do this.
Any pointers would be very appreciated. 

Also with the upcoming setting *sharedEntityManager* in Camel 2.16, would
this solve all my problems?



--
View this message in context: http://camel.465427.n5.nabble.com/spring-boot-jpa-entitymanagers-and-Java-DSL-tp5768055.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: spring boot, jpa, entitymanagers and Java DSL

Posted by erik_romson <er...@zenior.no>.
Yes but it works "as normal" I was just debugging and fooled by the proxies
when checking which one it was. It is the same.





--
View this message in context: http://camel.465427.n5.nabble.com/spring-boot-jpa-entitymanagers-and-Java-DSL-tp5768055p5768317.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: spring boot, jpa, entitymanagers and Java DSL

Posted by Henryk Konsek <he...@gmail.com>.
Hi,

We should check how Camel JPA component resolves the entity manager from
the Spring Boot registry. And then adjust that process, so it works more
natural for the Spring Boot applications. Can you raise a Jira ticket for
this issue?

Cheers!

pt., 12.06.2015 o 08:25 użytkownik erik_romson <er...@zenior.no> napisał:

> I suppose that.
> ----
> In Camel 2.3 the JpaComponent will auto lookup the EntityManagerFactory
> from
> the Registry which means you do not need to configure this on the
> JpaComponent as shown above. You only need to do so if there is ambiguity,
> in which case Camel will log a WARN.
> ----
> clearly states that it is the same entitymanager. The used one was just
> wrapped in so many proxy layers that I didn't understand it.
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/spring-boot-jpa-entitymanagers-and-Java-DSL-tp5768055p5768060.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: spring boot, jpa, entitymanagers and Java DSL

Posted by erik_romson <er...@zenior.no>.
Yes thanks

I found that out. I was fooled when debugging because the one it was using,
was wrapped in proxies, so that I didn't see that.

When you use spring boot, it uses the "normal one" derived from
"spring.datasource.url" etc or the one annotated with @Primary which ends up
as the one used by JPA. I haven't (thank good) tried to use multiple entity
managers....



--
View this message in context: http://camel.465427.n5.nabble.com/spring-boot-jpa-entitymanagers-and-Java-DSL-tp5768055p5768316.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: spring boot, jpa, entitymanagers and Java DSL

Posted by Wilson MacGyver <wm...@gmail.com>.
actually camel is pretty smart. if you create one and put it in the
registry, it will find it by type and use it automatically.

so in my startCamel code.

I do this

SimpleRegistry reg = new SimpleRegistry();

EntityManagerFactory factory =
Persistence.createEntityManagerFactory("camel",properties);

reg.put("jpaEntityManagerFactory", factory);

final CamelContext camelContext = new DefaultCamelContext(reg);


camel is the default JPA unit name.





On Wed, Jun 10, 2015 at 4:15 AM, erik_romson <er...@zenior.no> wrote:

> I suppose that.
> ----
> In Camel 2.3 the JpaComponent will auto lookup the EntityManagerFactory
> from
> the Registry which means you do not need to configure this on the
> JpaComponent as shown above. You only need to do so if there is ambiguity,
> in which case Camel will log a WARN.
> ----
> clearly states that it is the same entitymanager. The used one was just
> wrapped in so many proxy layers that I didn't understand it.
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/spring-boot-jpa-entitymanagers-and-Java-DSL-tp5768055p5768060.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Omnem crede diem tibi diluxisse supremum.

Re: spring boot, jpa, entitymanagers and Java DSL

Posted by erik_romson <er...@zenior.no>.
I suppose that.
----
In Camel 2.3 the JpaComponent will auto lookup the EntityManagerFactory from
the Registry which means you do not need to configure this on the
JpaComponent as shown above. You only need to do so if there is ambiguity,
in which case Camel will log a WARN.
----
clearly states that it is the same entitymanager. The used one was just
wrapped in so many proxy layers that I didn't understand it.




--
View this message in context: http://camel.465427.n5.nabble.com/spring-boot-jpa-entitymanagers-and-Java-DSL-tp5768055p5768060.html
Sent from the Camel - Users mailing list archive at Nabble.com.