How to cast String to long in Jpql i have used CAST(mem.employeeId AS
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Mohamed Azarudeen ZRank #297 · 8.5K reputationPosted May 14, 2023, 2:03 PM EDT
To cast a String to a long in JPQL, you can use the CAST function as follows:
SELECT e FROM Employee e WHERE e.employeeId = CAST(:id AS long)In this example, the :id parameter is a String that you want to cast to a long. The CAST function converts the parameter to a long before comparing it to the employeeId attribute.
Make sure that the value of the :id parameter is a valid long value, otherwise the query will fail with a ClassCastException.