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
Spring boot 带子列表的Spring-JPA投影_Spring Boot_Jpa_Response_Sublist - Fatal编程技术网

Spring boot 带子列表的Spring-JPA投影

Spring boot 带子列表的Spring-JPA投影,spring-boot,jpa,response,sublist,Spring Boot,Jpa,Response,Sublist,我对使用嵌套的“自定义”子列表创建带有自定义响应(spring投影)的本机查询有疑问,即我正在尝试使用嵌套的子列表生成JSON输出 子实体为: @Entity public class Child { @Id @GeneratedValue(strategy=GenerationType.AUTO) private int id; @NotNull @Column(nullable = false) private String firstNam

我对使用嵌套的“自定义”子列表创建带有自定义响应(spring投影)的本机查询有疑问,即我正在尝试使用嵌套的子列表生成JSON输出

子实体为:

@Entity
public class Child {
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private int id;

    @NotNull
    @Column(nullable = false)
    private String firstName;

    @NotNull
    @Column(nullable = false)

    private String secondName;

    @Enumerated(EnumType.STRING)
    private Gender gender;

    private Date dateOfBirth;

    private String phone;   

    @ManyToOne
    @JoinColumn(name="child_id")
    private List<Parent> parents = new ArrayList<Parent>();
//...
}
@实体
公营儿童{
@身份证
@GeneratedValue(策略=GenerationType.AUTO)
私有int-id;
@NotNull
@列(nullable=false)
私有字符串名;
@NotNull
@列(nullable=false)
私有字符串secondName;
@枚举(EnumType.STRING)
私人性别;
私人出生日期;
私人电话;
@许多酮
@JoinColumn(name=“child\u id”)
private List parents=new ArrayList();
//...
}
例如,父实体是:

@Entity
public class Parent {

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private int id;

    @NotNull
    @Column(nullable = false)
    private String firstName;

    @NotNull
    @Column(nullable = false)
    private String secondName;

    private Date dateOfRegistration;

    @OneToMany(fetch = FetchType.LAZY)
    private List<Child> child = new ArrayList<Child>();
    //...
}
@实体
公共类父类{
@身份证
@GeneratedValue(策略=GenerationType.AUTO)
私有int-id;
@NotNull
@列(nullable=false)
私有字符串名;
@NotNull
@列(nullable=false)
私有字符串secondName;
注册日期;
@OneToMany(fetch=FetchType.LAZY)
private List child=new ArrayList();
//...
}
投影界面:

public interface ChildProjectionInterface {

    public int getParentId();

    public Date getFirstName();

    public List<ChildResponse> getChildData();

    interface ChildResponse {

        public int getChildID();
        public String getFirstName();

    }
}
公共接口子项目接口{
public int getParentId();
公共日期getFirstName();
公共列表getChildData();
接口子响应{
public int getChildID();
公共字符串getFirstName();
}
}
查询(但显然不起作用):

@Query(value=“选择p.id作为parentId,p.firstName作为firstName,c.id作为childData.childId,c.firstName作为childData.firstName从父项p左键连接p.child_id=c.child_id上的子项c,p.secondName=:secondName”,nativeQuery=true)
列出GetListWithPublist(@Param(value=“secondName”)字符串secondName);

我在阅读、研究和尝试……但没有任何效果(我看到了,看到了“for json auto”子句,但没有看到spring jpa,等等)

您尝试过jpa fetch操作符吗

@Query("select p from parent p left join fetch p.child c where p.secondName = :secondName")

但是,这个想法并没有解决JPA自定义子列表的问题,问题是如何获取{parentId:1,firstName:“name”,{childId:1,firstName:“name”},{childId:2,firstName:“name”}等等。。。
@Query("select p from parent p left join fetch p.child c where p.secondName = :secondName")