HQL query with list of ENUM as parameter

3

Hello, I have the following problem, here is an example:

I have an entity Banda that has as attribute a list of genres 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 am trying to create a method that returns a List<Banda> by passing as a 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 solve this?

    
asked by anonymous 31.12.2014 / 03:43

1 answer

0

Use the setParameterList by associating its 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í!
    
31.12.2014 / 23:02