【发布时间】:2010-04-11 18:53:48
【问题描述】:
我想构建以下伪查询
Select a From APDU a where a.group.id= :id
group 是 APDUGroup.class 类型的 APDU 类中的一个字段。
我只想根据 APDUGroup 的 id 获取 APDU 列表。
如何使用标准 JPA 查询来做到这一点?
更新
是的,在发布到 S/O 之前,我已经尝试了上述查询并尝试了几个小时的其他变体。这是上面查询生成的 SQL:
SELECT t1.ID, t1.status, t1.type, t1.modified, t1.response, t1.expectedSize, t1.created, t1.description, t1.sequence, t1.name, t1.command, t1.recurring, t1.auth, t1.createdBy, t1.APDUGroup, t1.modifiedBy FROM APDUGroup t0, APDU t1 WHERE ((t0.ID = ?) AND (t0.ID = t1.APDUGroup))
查询看起来不错,但没有从我的表中选择。 我的测试数据库中至少有 100 个 APDUGroup = 1 的 APDU。
我使用 eclipselink 作为 JPA 提供程序。
【问题讨论】:
-
你写的查询试过了吗?
-
是的,我做到了,但我一无所获。查看我更新的问题
-
如果在 SQL 客户端中执行查询会发生什么?你能发布你的映射吗(我想知道为什么 eclipselink 在这里加入)?
标签: jpa object field associations