HQL query with ENUM list as parameter

Asked

Viewed 686 times

3

Hello, I have the following problem, follow an example:

I have an entity Banda which has as attribute a list of generos List<Generos> generos, Generos is an ENUM with the following values: ALTERNATIVE_ROCK("Alternative Rock"), CLASSIC_ROCK("Classic Rock"), HARD_ROCK("Hard Rock"), HEAVY_METAL("Heavy Metal"),PROGRESSIVE_ROCK("Progressive Rock");

I’m trying to create a method that returns a List<Banda> passing as parameter a list of ENUM List<Generos> using HQL... type public List<Banda> retornaBandasPorGenero(List<Generos> generos); but without success, what is the best way to resolve this?

1 answer

0


Use the method setParameterList when associating the respective parameter.

Example:

Generos[] paramGeneros = {Generos.ALTERNATIVE_ROCK, Generos.CLASSIC_ROCK};
IQuery minhaQuery = sessao.createQuery("from Banda b where b.Genero in (:colecaoGeneros)");
minhaQuery.setParameterList("colecaoGeneros", paramGeneros); // Olha ele aí!
  • Thanks @Jonathan Hudler!!! worked perfectly... had no knowledge of this method...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.