简体   繁体   English

在骆驼路线中使用多个JPA端点的最佳实践是什么

[英]What is the best practice for using multiple JPA endpoints in Camel route

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. 我有一条骆驼路线(Camel 2.19.2),它从一个JPA(休眠)端点提取数据,将其转换并将其存储到另一个JPA端点。 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. 当我调试它时,我看到Camel正在重用sourcejpa中的实体管理器,该实体管理器存储在交换属性中。

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? 最佳做法是什么?

This was how the camel-jpa component was designed. 这就是camel-jpa组件的设计方式。 It was not as intended to mix between different entity managers via different jpa components in the same routes. 在同一路线中,通过不同的jpa组件在不同的实体管理器之间进行混合并非意料之中的。

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. 已经有一个名为usePassedInEntityManager的选项,但仅用于消息头,这是由于SwitchYard的特殊要求而引起的,SwitchYard希望提供其自己的EntityManager ,Camel必须使用它。 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. 必须再次引入另一种选择,这也可能使用户感到困惑,尽管像您这样的用户使用两个不同的jpa组件可能会遇到与您相似的问题,并且可能无法发现他们应该删除该交换属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM