Sentencia JPQL que devuelve valor booleano
¿Es posible escribir una consulta JPQL como la siguiente:
select count(*) > 0 from Scenario scen where scen.name = :name
Que devolvería valores booleanos true/false dependiendo de si los criterios de relleno de entidad existen o no?
Me gustaría usar la consulta de esta manera:
boolean exists = entityManager.createQuery(query,Boolean.class).setParameter("name",name).getSingleResult();
La consulta de mi ejemplo simplemente no es sintácticamente correcta (error de análisis), pero ¿hay alguna forma correcta de hacer comprobaciones como esa en JPQL, que devolvería un valor booleano, o solo es posible en código Java?
26
Author: Piotr Sobczyk, 2012-08-21
3 answers
Sí, es posible con lo siguiente:
select case when (count(scen) > 0) then true else false end
from Scenario scen where scen.name = :name
39
Author: Mikko Maunu,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-08-21 09:55:28
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-08-21 09:55:28
¿Qué tal solo:
select count(scen) > 0
from Scenario scen where scen.name = :name
11
Author: Stefan Haberl,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-05-22 09:23:19
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-05-22 09:23:19
Estaba teniendo el mismo problema, entonces actualizé mi hibernación a 4.3.11.Final y ahora está funcionando.
1
Author: Error,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-08-27 15:28:08
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-08-27 15:28:08