Hibernate createSQLQuery。如何获得布尔值

时间:2014-06-20 06:35:46

标签: java mysql hibernate boolean biginteger

session.createSQLQuery("SELECT EXISTS 
(SELECT 1 FROM master.invoices WHERE currency_id = 17879)").list()

给了我BigInteger。 我怎样才能获得布尔值?

2 个答案:

答案 0 :(得分:1)

相应地尝试这个dude

SELECT CASE WHEN EXISTS(
SELECT * 
FROM 
master.invoices
WHERE currency_id = 17879
)
THEN CAST(1 AS BIT)
ELSE CAST(0 AS BIT) END

答案 1 :(得分:1)

以下是它的工作原理。

Boolean.valueOf((List<String>) session.createSQLQuery("SELECT IF
(SELECT 1 FROM master.invoices WHERE currency_id = 17879)
, 'true', 'false')").list());