|
Hibernate version: 3.1.2
Full stack trace of any exception that occurs:
Name and version of the database you are using: DB2 V8
I have this (legacy) setup:
Entity {
LexiconId
EntityKey}
Entry {
linked to Entity via {LexiconId, EntityKey}
text
}
Proposal {
linked to Entity via {LexiconId, EntityKey}
text
}
I need to create a request on the Text from either Entry or Proposal to return Entity values using the Criteria API
criteria.createAlias(PROPOSALS, "p", Criteria.LEFT_JOIN);
criteria.createAlias(ENTRIES, "e", Criteria.LEFT_JOIN);
criteria.add(Restrictions.disjunction().add(Restrictions.like("p.text", someEntryText)).add(
Restrictions.like("e.text", someEntryText)));
At the end, the Criteria receives a Projection on (Pk_Lex, Pk_id) and a Group By on the (Pk_Lex, Pk_id)
The generated sql is:
select this_.ENTITY_KEY as y0_, this_.LEXICON_ID as y1_, this_.ENTITY_KEY as y2_, this_.LEXICON_ID as y3_
from EntityTable this_
left outer join EntryTable e2_ on this_.ENTITY_KEY=e2_.ENTITY_KEY and this_.LEXICON_ID=e2_.LEXICON_ID
left outer join ProposalsTable p1_ on this_.ENTITY_KEY=p1_.ENTITY_KEY and this_.LEXICON_ID=p1_.LEXICON_ID
where (p1_.TEXT like ? or e2_.TEXT like ?)
group by this_.ENTITY_KEY, this_.LEXICON_ID,
order by e2_.TEXT ASC, p1_.TEXT ASC
But I never ask to order the results on the text value (which would be meaningless anyway). That request works well without the order by (obviously, because the e2.text is not referenced in the select clause). Why does Hibernate add this order clause? Is this a feature? Is this a bug from hibernate which doesn't see the Projections?
I'm puzzled
|