-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Using Projection.groupProperty() with alias
PostPosted: Fri May 05, 2006 3:12 pm 
Newbie

Joined: Fri May 05, 2006 2:52 pm
Posts: 1
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.