rakamakafo
rakamakafo

Reputation: 1154

JPQL query IS NOT NULL

I can't understand what can be wrong with following JPQL query:

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

Above query returns rows with debitAccount/creditAccount = null. How can I change it so that not to return rows with debitAccount/creditAccount = null

Upvotes: 3

Views: 3509

Answers (1)

rakamakafo
rakamakafo

Reputation: 1154

I've tried some different methods. And here how it worked out:

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

Upvotes: 1

Related Questions