我正在尝试过滤掉不属于AppService
login
个allowedusers
实体的用户的当前App
我的platform
返回的结果。
我采用的当前方法是Query-By-Example。 allowedusers
字段的过滤效果很好但@ManyToMany
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@JoinTable(name = "app_alloweduser",
joinColumns = @JoinColumn(name="apps_id", referencedColumnName="id"),
inverseJoinColumns = @JoinColumn(name="allowedusers_id", referencedColumnName="id"))
private Set<User> allowedusers = new HashSet<>();
public void setAllowedusers(Set<User> users) {
this.allowedusers = users;
}
过滤器似乎没有效果?
应用实体
@Override
@Transactional(readOnly = true)
public Page<AppDTO> findAll(RequestParams requestParams, Pageable pageable) {
App newApp = new App();
Example<App> appExample;
// set to current logged in user
User user = new User();
user.setLogin(SecurityUtils.getCurrentUserLogin());
Set<User> users = new HashSet<User>();
users.add(user);
newApp.setAllowedusers(users);
// set platform selected
if (requestParams.platform != null) {
newApp.setPlatform(requestParams.platform);
}
appExample = Example.of(newApp);
// find by example
Page<App> results = appRepository.findAll(appExample, pageable);
return results.map(app -> appMapper.toDto(app));
}
AppService服务
<TargetConnectionString>Data Source=XXX;User ID=XXX;Password=XXX;Pooling=False;MultipleActiveResultSets=False;Connect Timeout=60;Encrypt=False;TrustServerCertificate=True</TargetConnectionString>
答案 0 :(得分:0)
Spring Data JPA中的Query By Example不支持集合值属性
The documentation describes the following limitations of Query By Example强调我的:
仅支持字符串的开始/包含/结束/正则表达式匹配以及其他属性类型的完全匹配
因此,期望应用IN
逻辑肯定超出了当前实现的范围。
然后在同一份文件中再说:
目前,只有
SingularAttribute
属性可用于属性匹配。
这是一种令人困惑的陈述方式:仅适用于简单属性