I'm currently struggling with a query that I know it's possible, but due to my poor skills in SQL querys I can't really manage to find the right sentence.
I want to find all Territories from a certain Zone. Each Zone contains several Territories, but a Territory can belong to a Zone. The entities are as they follow:
public class Territory {
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
private Long id;
private String name;
private Long owned_player;
@OneToMany
private List<Territory> neighbors;
private int no_of_armies;
public Territory(String name) {
this.no_of_armies = 0;
this.neighbors = new ArrayList<>();
this.name = name;
//this.owned_player = new Player(0);
this.owned_player = null;
}
@Entity
public class Zone {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
private String name;
private String map;
//private int control_value;
@OneToMany
private List<Territory> territories;
public Zone(String name, String map) {
this.territories = new ArrayList<>();
this.name = name;
this.map = map;
//this.control_value = control_value;
}
The repo where I have to insert the query looks like this:
public interface TerritoryRepository extends JpaRepository<Territory,Long> {
@Query("????")
public List<Territory> findAllTerritoriesByZone(String zone);
}
I am trying to find that query that will return all territories that belong to Asia(China,Japan,Taiwan...) or Europe(Spain,France,Germany...) for example.
Thanks for your help and attention!