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