Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.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
Java Spring数据-JPA多嵌套对象_Java_Spring_Spring Boot_Spring Data Jpa_Spring Data - Fatal编程技术网

Java Spring数据-JPA多嵌套对象

Java Spring数据-JPA多嵌套对象,java,spring,spring-boot,spring-data-jpa,spring-data,Java,Spring,Spring Boot,Spring Data Jpa,Spring Data,我的班级结构如下: public class X { @Id private Long id; //One to one mapping private Y y; ....Some more attibutes } public class Y { @Id private Long id; //ManyToOne mapping private Z z; ....Some more attibutes } public class Z { @Id private Long

我的班级结构如下:

public class X {

@Id
private Long id;

//One to one mapping
private Y y;

....Some more attibutes

}

public class Y {

@Id
private Long id;

//ManyToOne mapping
private Z z;

....Some more attibutes

}

public class Z {

@Id
private Long id;

....Some more attibutes

}
现在我有了一个如下的Respository接口

public interface XRepository extends JPARepository<X, Long> {
    // This is not working,    
    public X findByIdAndYIdAndZId(Long xId, Long yId, Long zId);
    
    //This also doesn't work obviously for same reason as above one
    public X findYIdAndZId(Long yId, Long zId);

}
请帮助我如何构造这种场景的方法

字段Z在X中不存在,它在Y类中。因此,应该使用对象的完整路径作为Z的id

注:请考虑使用可理解的班级名称。我猜它们只是一个例子。

字段Z在X中不存在,它在Y类中。因此,应该使用对象的完整路径作为Z的id

注:请考虑使用可理解的班级名称。我想它们只是个例子。

您可以使用import org.springframework.data.mongodb.repository.Query;注释

 @Query("{$and : [{'y.id': ?0}, {'y.z.id': ?1 }]}")
 public X findByIdAndYIdAndZId(Long yId, Long zId);
您将对

有更多了解,您可以使用import org.springframework.data.mongodb.repository.Query;注释

 @Query("{$and : [{'y.id': ?0}, {'y.z.id': ?1 }]}")
 public X findByIdAndYIdAndZId(Long yId, Long zId);

你们会对

有更多的了解,我知道我可以用Query,但我想用method。我知道我可以用Query,但我想用method。
 @Query("{$and : [{'y.id': ?0}, {'y.z.id': ?1 }]}")
 public X findByIdAndYIdAndZId(Long yId, Long zId);