我尝试create a query in a project with Spring Data使用内部联接,并且我得到了一个"无法解析符号"错误。
我的项目结构是这个
我的实体是:
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
所以,我不想要Player
和Instance
之间的双向关系。
这是我的存储库:
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();
}
会产生以下错误:&#34;无法解析符号播放器&#34; (也是为了发生)。
我遇到了这个问题,which deals with a bidirectional mapping。评论的代码是尝试创建相同的查询,但没有起作用。我想知道,是否可以使用单向映射创建此类查询?