Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JPA查询多对一关联_Jpa_Object_Field_Associations - Fatal编程技术网

JPA查询多对一关联

JPA查询多对一关联,jpa,object,field,associations,Jpa,Object,Field,Associations,我想构建以下伪查询 从APDU a中选择a,其中a.group.id=:id 组是APDU类中类型为APDUGroup.class的字段 我只想根据APDUGroup的id获取apdu的列表 如何使用标准JPA查询来实现这一点 更新 是的,在S/O中过帐之前,我已经尝试了上述查询和其他变体数小时。以下是为上述查询生成的SQL: SELECT t1.ID, t1.status, t1.type, t1.modified, t1.response, t1.expectedSize, t1.creat

我想构建以下伪查询

从APDU a中选择a,其中a.group.id=:id

组是APDU类中类型为APDUGroup.class的字段

我只想根据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提供商。

考虑到以下实体:

@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;

    //...
}
以下查询将返回给定APDUGroup id的apdu列表:

select a from APDU a where a.group.id = :id

哦,等等,这是你的问题:)

你试过你写的问题了吗?是的,我试过了,但什么都没有。请参阅我更新的问题如果在SQL客户机中执行查询会发生什么?你能发布你的地图吗(我想知道为什么eclipselink会在这里加入)?天哪!你是对的!这是我的问题:),我在这里发布之前尝试过,但没有得到任何结果。我想也许还有其他的方法。我已经找到了我痛苦的根源。查询没有问题,服务层中的一些代码将关联的APDU组设置为null,以防止对象序列化为XML时出现循环图关系。谢谢你的帮助:)@Random很高兴你发现了(真正的)问题:)