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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate seems to add spurious order by clause
PostPosted: Thu Aug 02, 2007 9:14 am 
Newbie

Joined: Thu Aug 02, 2007 8:44 am
Posts: 3
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 02, 2007 9:44 am 
Newbie

Joined: Thu Aug 02, 2007 8:44 am
Posts: 3
This appears to be related to the following line in the hbm mapping file:
<set name="entries" inverse="true" order-by="TEXT ASC" lazy="true">

this looks like a bug in Hibernate to me, isn't it?


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

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.