我正在使用JPA和Spring从“角色”中检索“功能”列表。但是,当我想从我的应用程序中检索此列表时,它会返回一个空列表,而当我从SQL客户端执行生成的SQL请求时,我会检索一些内容
这是我的数据模型:
FEATURE: - 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。
请帮帮我吗?
答案 0 :(得分:0)
实际上,没关系。今天早上,我发现这是因为我从我的SQL客户端添加了条目而我没有提交事务。 :(
这只是......尴尬。