Ran*_*Joe 1 jpa field object associations
我想建立以下伪查询
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))
Run Code Online (Sandbox Code Playgroud)
该查询看起来还可以,但是没有从我的表中选择任何内容。我的测试数据库中至少有100个APDUGroup = 1的APDU。
我正在使用eclipselink作为JPA提供程序。
鉴于以下实体:
@Entity
public class APDU implements Serializable {
@Id
@GeneratedValue
private Long id;
@ManyToOne
private APDUGroup group;
//...
}
@Entity
public class APDUGroup implements Serializable {
@Id
@GeneratedValue
private Long id;
//...
}
Run Code Online (Sandbox Code Playgroud)
以下查询将返回给定APDUGroup ID的APDU列表:
select a from APDU a where a.group.id = :id
Run Code Online (Sandbox Code Playgroud)
哦,等等,这就是您的查询:)
| 归档时间: |
|
| 查看次数: |
6035 次 |
| 最近记录: |