2015-12-17 121 views
1

我不明白什麼可以不對以下JPQL查詢:JPQL查詢IS NOT NULL

StringBuilder sb = new StringBuilder("FROM FaPrimaryDocument AS t WHERE (t.debitAccount.id = :id or t.creditAccount.id = :id) " + 
       "AND t.debitAccount IS NOT NULL AND t.creditAccount IS NOT NULL "); 
Query q = em.createQuery(sb.toString(), FaPrimaryDocument.class) 
       .setParameter("id", id); 

List<FaPrimaryDocument> transactions = q.getResultList(); 

enter image description here

上面的查詢返回與debitAccount/creditAccount = null行。我如何改變它,以便不返回行debitAccount/creditAccount = null

+0

它看起來像查詢是正確的。 – Milkmaid

+0

等一下。我將發佈輸出 – Sher

+0

@Milkmaid,發佈更新 – Sher

回答

1

我試過一些不同的方法。在這裏它是如何解決的:

"SELECT t " + 
       "FROM FaPrimaryDocument AS t " + 
       "JOIN t.debitAccount AS da " + 
       "JOIN t.creditAccount AS ca " + 
       "WHERE " + 
        "((da.id = :id) OR (ca.id = :id)) " ;