Spring DATA JPA问题...我正在尝试编写查询以访问我的sql联接表中的数据。
我的联接表设置如下:
@Entity
@Table(name="WritingCompany")
public class WritingCompany {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "companyId")
private Long id;
// private String companyName;
@ManyToMany
@JoinTable(name = "Join-WritingCo-Carrier",
joinColumns = @JoinColumn(name="writingCo"),
inverseJoinColumns = @JoinColumn(name="carrier")
)
private Set<CarrierAppointment> carriers;
//...getters and setters
}
public class CarrierAppointment {
// ...
@ManyToMany(
cascade=CascadeType.ALL,
mappedBy = "companyName"
)
private Set<WritingCompany> companies;
public Set<WritingCompany> getCompanies() {
return companies;
}
public void setCompanies(Set<WritingCompany> companies) {
this.companies = companies;
}
//...
}
我不确定我需要为哪个类库编写查询...我试图从连接表中查找所有具有相同载体ID且与一个特定载体匹配的WritingCo名称。
Join Table是通过写作公司设置的,但是我觉得应该通过CarrierAppointment存储库访问它,因为我与运营商ID相匹配。
这是我在CarrierAppointment存储库中尝试过的操作,它引发了此错误(意外的令牌:在第1行第94列附近加入):
@Query("Select companyName FROM WritingCompany INNER JOIN CarrierAppointment ON Join-WritingCo-Carrier.carrier= CarrierAppointment.CarrierAppointmentId")
List<CarrierAppointment> findCarrierAppoinmentFromJoin(CarrierAppointment carrier);
@Query("SELECT writingCo FROM Join-WritingCo-Carrier WHERE carrier= CarrierAppointment.CarrierAppointmentId")
List<CarrierAppointment> findCarrierAppoinmentFromJoin(CarrierAppointment carrier);
然后我在WritingCompanyRepository中尝试了此操作,它也引发了类似的错误:
@Query("Select companyName FROM WritingCompany INNER JOIN CarrierAppointment ON Join-WritingCo-Carrier.carrier= CarrierAppointment.CarrierAppointmentId")
List<WritingCompany> findAllWithDescriptionQuery(CarrierAppointment carrier);