JPQL查询不是NULL

时间:2015-12-17 07:53:05

标签: java jpa jpql

我无法理解以下JPQL查询可能出现的问题:

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();

DEMO

以上查询返回debitAccount/creditAccount = null行。如何更改它以便不返回debitAccount/creditAccount = null

1 个答案:

答案 0 :(得分:1)

我尝试了一些不同的方法。在这里它是如何运作的:

<div class="col-sm-4">  
        <?php if ( $the_query->have_posts() ): ?>
        <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>                                   
          <h2 class="special-project-title"><?php the_title()?></h2> <br/>
         <div class="post-meta special-project-meta"><?php mida_post_meta()?></div><br/>
         <a class="more-link spaciel-project-more" href="<?php echo the_permalink() ?>"><?php echo __('Read More', 'mida')?></a><br/>
    <?php endwhile; endif;?>    
    <?php wp_reset_query(); ?>  
</div>