Camel 没有该功能,因为 JPA 支持命名查询。你可以按照这些思路做一些事情。
from("direct:start")
.pollEnrich("jpa:" + MyEntity.class.getName() + "?consumeDelete=false&consumer.namedQuery=myNamedQuery&consumer.parameters=#params", new MyAggregationStrategy())
.log(LoggingLevel.INFO, "call my entity toString method ${body}");
//spring context OR you can use camel registry
<util:map id="params" key-type="java.lang.String">
<entry key="param1" value="1"/>
<entry key="param2" value="2"/>
</util:map>
//JPA model
@Entity
@Table(name = "MyTable")
@NamedQuery(name = "myNamedQuery", query = "SELECT t FROM MyTable t WHERE t.columnName1 = :param1 AND t.columnName2 = :param2")
public class MyEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "PrimaryKey", updatable = false, nullable = false, length = 20)
private String primaryKey;
@Column(name = "Param1", length = 5)
private String param1;
@Column(name = "Param2", length = 5)
private String param2;
//removed setters getters, hascode, equals, and toString for brevity
}