Hi everyone,
i've been using hibernate and some days ago i tried to use it with a VIEW. In the view i put a rownum to be the unique id and mapped it with a primary key. Ok this is working!
This View has a lot of fields, let me say 40-50. I'm going to use this view to make a page to filter lots of things... anyways...
The problem is that i just have to bring from as a result for the user only 7 or 12 fields depending on the search. "Ok", i thougth, "just use the projection and a Result Transformer", and it works fine.
The problem is, when i do something like this:
Code:
public List<ContratoView> list(ContratoView cv)
{
Criteria crit = getSession().createCriteria(ContratoView.class);
Example ex = Example.create(cv);
ex.enableLike(MatchMode.ANYWHERE);
ex.ignoreCase();
ex.excludeZeroes();
crit.add(ex);
crit.setProjection(
Projections.projectionList()
.add(Projections.groupProperty("codigoContratoRes"),"codigoContratoRes")
.add(Projections.groupProperty("codigoClienteRes"),"codigoClienteRes")
.add(Projections.groupProperty("razaoSocialRes"),"razaoSocialRes")
.add(Projections.groupProperty("dataEntradaContratoRes"),"dataEntradaContratoRes")
.add(Projections.groupProperty("dataVencimentoContratoRes"), "dataVencimentoContratoRes")
.add(Projections.groupProperty("tipoContratoRes"), "tipoContratoRes")
.add(Projections.groupProperty("nomePlanoRes"), "nomePlanoRes")
.add(Projections.groupProperty("cnpjRes"), "cnpjRes")
);
}
crit.setResultTransformer(new AliasToBeanResultTransformer(ContratoView.class));
List<ContratoView> results = crit.list();
return results;
}
The problem occurs because of the Example (query by Example), when i filter with the same column that i'm using in the group by Hibernate uses the Alias in the where clause, but you can't use an alias in the where that where the problem is. When i don't use any atribute which are in the group the query are build perfectly.
In fact, this post is to know from you, if this is a bug, or this is the expected.
I have put it to work duplicatin the fields in the View.
Thanks cya.