I'm trying to create a query in a project with Spring Data that uses an inner join, and I'm getting a "Can't resolve symbol" error.
My project structure is this
My entities are:
import javax.persistence.*;
@Entity
@Table(name="players")
public class Player {
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
private Long id;
private String name;
@ManyToOne(fetch= FetchType.LAZY)
@JoinColumn(name="team_id")
private Team team;
// Getters, setters, etc
import javax.persistence.*;
@Entity
@Table(name="incidences")
public class Incidence {
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
private Long id;
@ManyToOne
@JoinColumn(name = "player_id")
private Player player;
private IncidenceType type;
private IncidenceStatus status;
public enum IncidenceStatus {
ACTIVE, COMPLETED
}
// Getters, setters, etc
So, i don't want a bidirectional relationship between Player
and Instance
.
And this is my repository:
import com.github.juanmougan.worldcup.api.model.Player;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import java.util.List;
public interface PlayerRepository extends CrudRepository<Player, Long> {
//@Query("SELECT p.id, p.name, p.team_id FROM Player p inner join p.incidences i WHERE i.status = 'ACTIVE'")
@Query("SELECT p.id, p.name, p.team_id FROM Player p inner join Incidence i WHERE i.status = 'ACTIVE'")
List<Player> findPlayersWithActiveIncidences();
}
Which yields the following error: "Can't resolve symbol Player" (also for the Incidence).
I came across this question, which deals with a bidirectional mapping. The commented code was an attempt to create the same query, that didn't work. I'm wondering, is it possible to create such query with a unidirectional mapping?