如何从父母那里取回孩子?
假设我有父类和子类。我想从父母一方检索孩子的名单。
这是我的家长班。
+import ...
@Entity
public class Parent {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private Long id;
@OneToMany(mappedBy="parent", cascade = CascadeType.REMOVE, orphanRemoval = true)
private List<Child> Childs = new ArrayList<>();
private String name;
* Getter and Setter are hide
}
这是我的父母孩子。
+import ...
@Entity
public class Child {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private Long id;
@ManyToOne()
private Parent parent;
private String childNote;
* Getter and Setter are hide
}
这是我的存储库
@Repository
public interface ParentRepository extends JpaRepository<Parent, Long> {
@Query(value = "SELECT p.childs FROM Parent p where p.id =:id")
List<Child> findxx(Long id);
}
这给了我一个错误:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-03-05 00:59:16.281 ERROR 444 --- [ main] o.s.boot.SpringApplication : Application run failed
潇潇雨雨
相关分类