From 9240342b366db9999f11659a1f1c396ba418ad78 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Sat, 7 Jan 2023 18:51:03 +0100 Subject: Adds --- .../TSDWL/SPRING/petshop/src/main/java/it/dmi/tsdw/petshop/Race.java | 1 + .../main/java/it/dmi/tsdw/petshop/repositories/PetRepository.java | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'Year_3/TSDWL/SPRING/petshop/src') diff --git a/Year_3/TSDWL/SPRING/petshop/src/main/java/it/dmi/tsdw/petshop/Race.java b/Year_3/TSDWL/SPRING/petshop/src/main/java/it/dmi/tsdw/petshop/Race.java index 4f08fe9..764eda6 100644 --- a/Year_3/TSDWL/SPRING/petshop/src/main/java/it/dmi/tsdw/petshop/Race.java +++ b/Year_3/TSDWL/SPRING/petshop/src/main/java/it/dmi/tsdw/petshop/Race.java @@ -6,6 +6,7 @@ import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; +import javax.persistence.OneToMany; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; diff --git a/Year_3/TSDWL/SPRING/petshop/src/main/java/it/dmi/tsdw/petshop/repositories/PetRepository.java b/Year_3/TSDWL/SPRING/petshop/src/main/java/it/dmi/tsdw/petshop/repositories/PetRepository.java index 145e47e..d2ca7c9 100644 --- a/Year_3/TSDWL/SPRING/petshop/src/main/java/it/dmi/tsdw/petshop/repositories/PetRepository.java +++ b/Year_3/TSDWL/SPRING/petshop/src/main/java/it/dmi/tsdw/petshop/repositories/PetRepository.java @@ -1,6 +1,7 @@ package it.dmi.tsdw.petshop.repositories; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; import it.dmi.tsdw.petshop.Pet; @@ -8,7 +9,9 @@ import it.dmi.tsdw.petshop.Race; @Repository public interface PetRepository extends JpaRepository{ - public Race findByRaceId(Long race_id); + @Query(value = "SELECT p FROM Pet p WHERE race_id = ?1") + public Race searchRace(Long race_id); + public Race findByRaceName(String name); } -- cgit v1.2.3-18-g5258