[英]Spring data jpa like query compatible with Oracle and Postgres
我有一个 Spring 数据存储库,方法如下。
Page<FooEntity> findAllByTenantNameAndEventTypeContainingIgnoreCaseAndReferenceContainingIgnoreCaseAndSourceServiceInIgnoreCase( //NOSONAR
String tenantName,
String eventType,
String reference,
List<String> services,
Pageable pageable);
只要字段的值: tenantName 、 eventType 、 reference为空,在 Postgres 中它就会返回预期的列表。
但是对于 Oracle 数据库,它不返回数据。
我知道这是因为Oracle 在内部将空字符串转换为 null。 因为它,我没有得到任何数据。
如何使此查询方法与Postgres和Oracle兼容?
Unfortunately, there is no fix for this on database level - see https://docs.oracle.com/cd/B28359_01/server.111/b28286/sql_elements005.htm#SQLRF51081 where even Oracle acknowledges the fact that this is not optimal:
Oracle 数据库当前将长度为零的字符值视为 null。 但是,在未来的版本中,这可能不会继续存在,并且 Oracle 建议您不要将空字符串视为空值。
因此,对于您的问题,我想您需要找到一种在应用程序级别上解决此问题的方法。
问题未解决?试试以下方法:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.