我的应用程序中有以下实体:
@Entity
public class A implements Serializable {
...
@OneToMany(mappedBy = "thread", fetch = FetchType.LAZY)
private List<B> comments;
...
当我获得实体 A 的任何实例时,我必须根据一些复杂的条件获得 B 的子列表。我尝试过使用这样的@Where 子句:
@OneToMany(mappedBy = "thread", fetch = FetchType.LAZY)
@Where(clause =
"CASE " +
" WHEN moderationType = 'PRE' AND state = 1 THEN 1" +
" WHEN moderationType = 'POST' AND state IN (0,1,4) THEN 1" +
" ELSE 0" +
" END = 1 "
)
private List<B> comments;
我遇到的问题是这个条件不仅涉及B实体,还涉及A(属性moderationType属于A,属性状态属于B)。当我尝试获取任何 A 实体时,我收到以下错误,因为属性 moderationType 不属于 B:
javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: ORA-00904: "B2_"."MODERATIONTYPE": invalid identifier
有没有办法在 @Where 子句中引用两个实体(父实体和被引用实体)?
非常感谢您提前