gpt4 book ai didi

Java JPA - "Query argument id not found in the list of parameters provided during query execution"

转载 作者:行者123 更新时间:2023-12-02 02:41:30 25 4
gpt4 key购买 nike

我有一个名为 Pilot 的实体类,具有以下定义的命名查询:

@NamedQuery(name="Pilot.findById", query="SELECT p FROM Pilot p where p.id = :id")

另一个名为 Flight 的命名查询:

@NamedQuery(name="Flight.findById", query="SELECT f FROM Flight f where f.id = :id")

然后我有一个方法可以执行以下操作:

TypedQuery<Flight> fQuery = em.createNamedQuery("Flight.findById", Flight.class);
fQuery.setParameter("id", Integer.parseInt(flightId));

Flight f = fQuery.getSingleResult();

TypedQuery<Pilot> pQuery = em.createNamedQuery("Pilot.findById", Pilot.class);
fQuery.setParameter("id", Integer.parseInt(pilotId));

Pilot p = pQuery.getSingleResult();

但由于某种原因,当我调用它时,我收到错误:

...
Caused by: java.lang.IllegalStateException: Query argument id not found in the list of parameters provided during query execution.
...

可能是什么问题?

最佳答案

看起来像是剪切和粘贴错误...

TypedQuery<Pilot> pQuery = em.createNamedQuery("Pilot.findById", Pilot.class);
fQuery.setParameter("id", Integer.parseInt(pilotId));
^^^^^^

您在 fQuery 上设置了两次 ID。尝试将飞行员更改为 pQuery。像这样:

TypedQuery<Pilot> pQuery = em.createNamedQuery("Pilot.findById", Pilot.class);
pQuery.setParameter("id", Integer.parseInt(pilotId));
^^^^^^

关于Java JPA - "Query argument id not found in the list of parameters provided during query execution",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45379818/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com