我试图让一个电台投影包括一个相关的标识列表。以下是我的域:
@Table(name = "Station")
public class Station implements Serializable {
@Id
@Column(name = "Id")
private int id;
@OneToMany(cascade = CascadeType.ALL,
fetch = FetchType.LAZY,
mappedBy = "station")
private Set<Logo> logos;
}
@onetomany相关标识:
@Table(name = "Logo")
public class Logo {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@Transient
private String fullUrl; // calculated
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "StationId", nullable = false)
private Station station;
}
我的存储库和查询如下:
@Query(value = "SELECT s.id AS Id, s.logos As Logos FROM Station s JOIN s.users su WHERE su.username = ?1")
Collection<StationListViewProjection> findStationsByUsername(String username);
我的电台预测需要id和一个logoprojections列表
@Projection(name = "StationListViewProjection", types = Station.class)
public interface StationListViewProjection {
int getId();
Set<LogoProjection> getLogos();
}
logoProjection只需要url
@Projection(name = "LogoProjection", types = Logo.class)
public interface LogoProjection {
String getFullUrl();
}
当我执行查询时,会得到一个奇怪的响应:
mysqlsyntaxerrorexception:您的sql语法有错误;请查看与mysql服务器版本相对应的手册,以获取在“as col_5_0”附近使用的正确语法。作为Col_6_0_u,StationLog3_u.id作为ID1_20_0_u'