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.