使用JPA查询数据库以获取空值

时间:2018-12-08 17:35:33

标签: spring spring-data-jpa jpql

数据库中的值有时可以为Title: Some TITLE Description:A Storm application is designed as a "topology" in the shape of a directed acyclic graph (DAG) with spouts and bolts acting as the graph vertices. Edges on the graph are named streams and direct data from one node to another. Together, the topology acts as a data transformation pipeline. At a superficial level the general topology structure is similar to a MapReduce job, with the main difference being that data is processed in real time as opposed to in individual batches. Additionally, Storm topologies run indefinitely until killed, while a MapReduce job DAG must eventually end. url: https://www.someurl.com Title: Some TITLE Description:A Storm application is designed as a "topology" in the shape of a directed acyclic graph (DAG) with spouts and bolts acting as the graph vertices. Edges on the graph are named streams and direct data from one node to another. Together, the topology acts as a data transformation pipeline. At a superficial level the general topology structure is similar to a MapReduce job, with the main difference being that data is processed in real time as opposed to in individual batches. Additionally, Storm topologies run indefinitely until killed, while a MapReduce job DAG must eventually end. url: http://www.someurl.com ,有时不能为。我如何找回它? 这是我的尝试,这让我感到惊讶:

NULL

测试正常:

@Repository
public interface AddressRepo extends JpaRepository<Address, Long>{

    @Query("select count(a) > 0 from Address a where a.street = :street")
    boolean testtest(@Param("street") String street);
}

测试失败:

// given
address = new Address("WIELKA WARSZAAAWA", "Bokserska", "xxx", "50-500");
// when
addressRepo.save(address);
// then
assertTrue(addressRepo.testtest("Bokserska")); // OK

1 个答案:

答案 0 :(得分:2)

JPQL 无法翻译以下声明:

WHERE a.street = null

对于此SQL:

WHERE a.street IS null

因此,您需要创建一个新的@Query

select count(a) > 0 from Address a where a.street IS NULL

手动安装JPQL字符串或使用条件创建动态查询也是不错的选择。