-->
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: Query by Criteria using Wrong Alias with Sum and group by
PostPosted: Wed Oct 30, 2013 5:32 am 
Newbie

Joined: Wed Jul 07, 2010 10:01 am
Posts: 5
Hello,
I'm building a query trough Hibernate's Criteria, and the output select is using a wrong alias to filter one of my fields.
Here is the select generated

Code:
    select
        sum(this_.coluna_3) as y0_,
        this_.coluna_2 as y1_
    from
        TESTE_CRITERIA this_
    where
        (
            y1_ like ?
        )
    group by
        this_.coluna_2

As you can see, the where clause with the alias y1_ is wrong. This query will not run in an Oracle Database, and returns the following error:

Quote:
ORA-00904: "Y1_": invalid identifier


I'm building the query with the following code:
Code:
        TesteCriteria testeCriteria = new TesteCriteria();
        testeCriteria.setColuna2("DATA 2%");
        Criteria crit = ((Session) emFactory.createEntityManager().getDelegate()).createCriteria(testeCriteria.getClass());
        Example example = Example.create(testeCriteria).enableLike();
        crit = crit.add(example);
        ProjectionList projlist = Projections.projectionList();
        projlist.add(Projections.sum("coluna3").as("coluna3"));
        projlist.add(Projections.groupProperty("coluna2").as("coluna2"));
        crit.setProjection(projlist);
        List<TesteCriteria> listResult = crit.list();
        Assert.assertNotNull(listResult);
        Assert.assertFalse(listResult.isEmpty());


TesteCriteria is a simple Entity Object, defined as below:
Code:
@Entity
@Table(name = "TESTE_CRITERIA")
public class TesteCriteria extends TaxitEntityBase {

    @Id
    @Column(name="coluna_1")
    private Long coluna1;
   
    @Column(name="coluna_2")
    private String coluna2;
   
    @Column(name="coluna_3")
    private BigDecimal coluna3;
   
    /**
     * Coluna <b> <PK->FK></b>.
     */
    @OneToMany(mappedBy = "testeCriteria", cascade = { CascadeType.ALL })
    @Cascade(value = {org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
    private List<TesteCriteriaFilho> testeCriteriaFilhoCollection;
...
}


Any idea on what I'm doing wrong ?

Thanks a lot !

John


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.