Sony
Sony

Reputation: 7196

Calling named query with `in()`, in Hibernate

This is my Hibernate namedQuery:

@NamedQuery(name = "getLanguagesForIds", query = "select l from Language l where l.languageId in(:ids)")

When I tried to execute the query, Hibernate is throwing exception:

java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer

I am passing the language ids as comma separated, like 1,2. Does anyone know how to solve this issue?

Upvotes: 0

Views: 178

Answers (1)

Har Krishan
Har Krishan

Reputation: 273

use List = new ArrayList to hold the ids and pass that as parameter value rather than comma separated string.

Upvotes: 1

Related Questions