JPA中的COALESCE namedQuery [英] COALESCE in JPA namedQuery

查看:1289
本文介绍了JPA中的COALESCE namedQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下namedQuery

I have the following namedQuery

select new test.entity.Emp(COALESCE(k.projectId,'N')
as projectId, k.projectName) from Emp o inner join o.projects k 

但是我遇到错误

期望RIGHT_ROUND_BRACKET,找到'('

expecting RIGHT_ROUND_BRACKET, found '('

如何处理namedQuery中的COALESCE?

How to handle COALESCE in namedQuery?

在JPA中还有其他方法可以处理空值吗?

Are there any other ways to handle null values in JPA?

推荐答案

Coalesce是由JPA 2.0 API支持.

Coalesce is supported by JPA 2.0 API.

new构造是Hibernate专有的,不一定在所有JPA实现中都受支持.首先尝试查询而不尝试构造对象:

The new construct is proprietary to Hibernate, not necessarily supported in all JPA implementations. First try the query without also trying to construct an object:

select COALESCE(k.projectId,'N') as projectId, k.projectName from Emp o inner join o.projects k

这篇关于JPA中的COALESCE namedQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆