有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何防止包含字符串构造函数的JPA查询在空字符串值仅可用时引发NullPointerException

我有以下JPA查询:选择新java。lang.String(c.country)按c.country从联系人c组按c.country排序按c.country排序

当Contact表中的一行为country字段保留空值时,上面JPA查询中的字符串构造函数会抛出NullPointerException

由于联系人表中的country字段允许空值,有没有办法通过代码阻止它,并且仍然使用命名查询


共 (1) 个答案

  1. # 1 楼答案

    那怎么办

    select c.country from Contact c where c.country is not null group by c.country order by c.country