Reputation: 123
I have a camel route (Camel 2.19.2), that extracts data from one JPA (Hibernate) endpoint, transforms it and stores it to another JPA endpoint. Like this
from("direct:start")
.to("sourcjpa:com.somepackage.SomeEntity?persistenceUnit=mySource&namedQuery=myQuery")
.bean("transformBean")
.to("targetjpa:com.anotherpackage.AnotherEntity");
This fails with error telling me that the target entity class is not known by the entity manager. When I debug it I see that Camel is reusing the entity manager from the sourcejpa, which is stored in the exchange properties.
If I change the route like this:
from("direct:start")
.to("sourcjpa:com.somepackage.SomeEntity?persistenceUnit=mySource&namedQuery=myQuery")
.bean("transformBean")
.removeProperty(JpaConstants.ENTITY_MANAGER)
.to("targetjpa:com.anotherpackage.AnotherEntity");
It works as I expected.
Am I doing it wrong?
What is the best practice for this?
Upvotes: 0
Views: 569
Reputation: 55535
This was how the camel-jpa component was designed. It was not as intended to mix between different entity managers via different jpa components in the same routes.
So you are correct by removing that property.
There is already an option named usePassedInEntityManager
but that is only for message header which was due to special requirement from SwitchYard which wanted to provide their own EntityManager
which Camel must use. However that options does not apply to the exchange property.
Having to introduce yet another option again, may confuse users as well, albeit users like you with two different jpa components may hit similar issue as you did, and may not be able to find out that they should remove that exchange property.
Upvotes: 1