我在使用 QueryDSL 过滤以下实体时遇到问题:
@Entity
@Table(name = "newidea")
@Cacheable(true)
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class NewIdea extends DomainObject implements Membership {
//id, other attributes etc
@OneToMany(fetch = FetchType.LAZY, mappedBy = "key.idea", cascade = CascadeType.ALL, orphanRemoval = true)
@QueryInit("newIdeaParticipations.key.student")
private Set<NewIdeaParticipation> newIdeaParticipations = new HashSet<NewIdeaParticipation>();
//constructor, getters, setters etc
}
@Entity
@Table(name = "newidea_student")
@AssociationOverrides({
@AssociationOverride(name = "key.student",
joinColumns = @JoinColumn(name = "role_id")),
@AssociationOverride(name = "key.idea",
joinColumns = @JoinColumn(name = "idea_id")) })
public class NewIdeaParticipation implements Serializable {
@EmbeddedId
@QueryInit("student")
private NewIdeaParticipationId key = new NewIdeaParticipationId();
//other attributes, constructor, getters, setters etc
}
@Embeddable
public class NewIdeaParticipationId implements Serializable {
@ManyToOne
private Student student;
@ManyToOne
private NewIdea idea;
}
过滤器:
private BooleanExpression authorFilter(Student author){
// return QNewIdea.newIdea.newIdeaParticipations.any().key.student.eq(author); //NPE any is not null, but any.students attributes is null, and any.key.student is null
// return QNewIdea.newIdea.newIdeaParticipations.any().user.eq(author.getUser()); //hibernate.QueryException (any is null)
}
顶级查询异常:
底部查询异常:
我究竟做错了什么?我错过了什么吗?