0
我正在使用JPA和Spring從「角色」中檢索「特性」列表。但是,當我想從我的應用程序獲取此列表,它返回我的空單,而我找回的東西,當我從SQL客戶端執行生成的SQL請求用Spring返回的空集合JPA
這裏是我的數據模型:
特點: - ID(PK) - 姓名 - 描述
AD_ROLE: - ID(PK) - 姓名
FEATURE_AD_ROLE - FEATURE_ID(FK到FEATURE.id) - ad_role_id(FK到AD_ROLE.id)
我的實體是:
@Entity
@Table(name = "FEATURE")
public class Feature implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private int id;
private String name;
private String description;
@ManyToMany
@JoinTable(name = "FEATURE_AD_ROLE", joinColumns = @JoinColumn(name = "FEATURE_ID", referencedColumnName = "ID"), inverseJoinColumns = @JoinColumn(name = "AD_ROLE_ID", referencedColumnName = "ID"))
private Collection<ADRole> adRoles;
// getter/setters
}
@Entity
@Table(name = "AD_ROLE")
public class ADRole implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private int id;
private String name;
@ManyToMany(mappedBy = "adRoles")
private List<Feature> features;
// getters/setters
}
吾道:
@Repository
public interface FeatureDao extends JpaRepository<Feature, Long> {
@Query("SELECT f FROM Feature f JOIN f.adRoles fa WHERE fa.name = :adProfile")
public Collection<Feature> getFeaturesByADProfile(@Param("adProfile") String adProfile);
}
這會產生這樣的SQL請求:
select feature0_.id as id1_1_, feature0_.description as description2_1_, feature0_.name as name3_1_ from FEATURE feature0_ inner join FEATURE_AD_ROLE adroles1_ on feature0_.id=adroles1_.FEATURE_ID inner join AD_ROLE adrole2_ on adroles1_.AD_ROLE_ID=adrole2_.id where adrole2_.name=?
當我從SQL客戶端執行此請求,我可以看到結果。
我的DBMS是Oracle。
你能幫助我嗎?