我正在使用JPA namedQuery从数据库中选择数据。
@NamedQuery(name = "Concept.findByRefTableNull", query = "SELECT c FROM Concept c WHERE c.conceptName = :conceptName and c.refTable = :refTable"),
///
List<Concept> attributeList
= em.createNamedQuery("Concept.findByRefTableNull")
.setParameter("conceptName", "student").
setParameter("refTable", null).
getResultList();
System.out.println(attributeList.size()); //return 0
列表大小为0,但我确定它应该有记录。原因是refTable。如何在JPA中查询值为空的列?
谢谢。
最佳答案
只需将查询更改为
@NamedQuery(name = "Concept.findByRefTableNull", query = "SELECT c FROM Concept c WHERE c.conceptName = :conceptName and c.refTable IS NULL"),
关于java - 如何在JPA中查询值为空的列?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6325213/