Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

COALESCE in JPA 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 

However I am getting error

expecting RIGHT_ROUND_BRACKET, found '('

How to handle COALESCE in namedQuery?

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

like image 534
Jacob Avatar asked Dec 17 '14 15:12

Jacob


1 Answers

Coalesce is supported by JPA 2.0 API.

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
like image 80
gknicker Avatar answered Sep 17 '22 14:09

gknicker