-->
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.  [ 3 posts ] 
Author Message
 Post subject: why they are not the same?
PostPosted: Sun Aug 29, 2004 7:03 am 
Newbie

Joined: Sun Aug 29, 2004 6:34 am
Posts: 2
Hibernate version: 2.1.6

Mapping documents:
Code:
<hibernate-mapping>
   <class name="Topic">
   
      <id name="id" type="int" column="topic_id">
         <generator class="native" />
      </id>
      
      <property name="title" type="string" />

   </class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():

Code:
   Topic t1 = new Topic("one");
   Topic t2 = new Topic("two");
   Topic t3 = new Topic("three");

   s.save(t1);
   s.save(t2);
   s.save(t3);

   Iterator iter1 = s.createQuery("from Topic order by :orderby")
       .setString("orderby", "title")
       .iterate();

   Iterator iter2 = s.createQuery("from Topic order by title")
       .iterate();

   printIterator("Iterator One", iter1);
   printIterator("Iterator Two", iter2);

Name and version of the database you are using: MySQL 4.0.18

The output result is:

Code:
Iterator One:

   Topic: id=1 title=one
   Topic: id=2 title=two
   Topic: id=3 title=three

Iterator Two:

   Topic: id=1 title=one
   Topic: id=3 title=three
   Topic: id=2 title=two


The problem:

The first query is not ordered, but I think it should be ordered.

Is it a bug, or just my mistake?

btw: there is a misleading sentence in the book Hibernate in Action:

On page 284 (ebook), section 7.3.2, the book said:

Quote:
Note that the left keyword is optional in HQL, so we could rewrite the previous examples using join fetch.

"join fetch" and "left join fetch" are not the same, the former is an inner join and the latter is a left outer join. But from the sentence above, I can't deduce the difference.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 29, 2004 7:56 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
You are trying to do something that is not possible in JDBC. Your driver converts the first query to:

Code:
   from Topic order by 'title'


Also, correct HQL is:

Code:
   from Topic t order by t.title


The alias is not optional for property names.

P.S. Please don't use words like "bug", its quite irritating. Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 29, 2004 11:22 am 
Newbie

Joined: Sun Aug 29, 2004 6:34 am
Posts: 2
Thanks!

I will not use that word again :-)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.