Witam
Jestem w trakcie robienia projektu SpringBoot-Angular ktrego zadaniem jest dodawanie odczytywanie danych o rodzinie. I mam problem ponieważ :
posiadam klasę encję :
package pl.pawel.mazur.family.inteca.familiInteca.Model;
import javax.persistence.*;
@Entity
public class Child {
private String firstName;
@Id
@GeneratedValue
private int ID;
private String pesel;
private String secondName;
private String sex;
@OneToOne
private Family family;
@OneToOne
@JoinColumn (name = "fatherid")
private Father father;
public Child (){super();}
public Child(String firstName, String pesel, String secondName, String sex, Family family, Father father) {
this.firstName = firstName;
this.pesel = pesel;
this.secondName = secondName;
this.sex = sex;
this.family = family;
this.father = father;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public int getID() {
return ID;
}
public void setID(int ID) {
this.ID = ID;
}
public String getPesel() {
return pesel;
}
public void setPesel(String pesel) {
this.pesel = pesel;
}
public String getSecondName() {
return secondName;
}
public void setSecondName(String secondName) {
this.secondName = secondName;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public Family getFamily() {
return family;
}
public void setFamily(Family family) {
this.family = family;
}
public Father getFather() {
return father;
}
public void setFather(Father father) {
this.father = father;
}
}
Oraz JPA repository :
package pl.pawel.mazur.family.inteca.familiInteca.Model;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface ChildRepository extends JpaRepository <Child , Integer > {
public List<Child> findByFather(Father father);
public List<Child> findByFirstNameOrPeselOrSecondNameOrSex(String firstName, String pesel, String secondName, String sex);
@Query(value = "select from child", nativeQuery = true )
List<Child> findAllActiveUsersNative();
}
W bazie danych wyglada to tak :
https://zapodaj.net/15c30751b4a16.png.html
i chodzi to że mam sześć dzieci które należy co trzech rodzin i chciałbym aby JPA pobrało z bazy ojców bez powtórzeń i aby to zrobić można w postgres wpisać
select distinct fatherid from child ;
i zostają zwróceni ojcowie bez powtórzeń
https://zapodaj.net/cbb5afc1b04e1.png.html
I teraz chodzi mi o to żeby to zaimplementować jakoś w repozytorium z tym ze nie mam pojęcia jak.
Stos jaki zwraca ide http://www.wklejto.pl/614251
Proszę link do projektu oraz na youtube z wideo problemu
https://youtu.be/VWzw9F-Haa4
https://github.com/mpawel1993/familyInteca
Użyte JSONY
localhost:8080/CreateFamily
localhost:8080/AddFatherToFamily
{"date":"data",
"firstName":"pierwszeImie",
"pesel":"pesel",
"secondName":"secImie"}
localhost:8080/AddChildToFamily
{"firstName":"pierwsze",
"pesel":"pesel",
"secondName":"secondName",
"sex":"male"}
localhost:8080/SearchChild
{"firstName":"pierwsze",
"pesel":"pesel",
"secondName":"secon