Beginner |
|
Joined: Tue Jan 27, 2004 8:33 am Posts: 29
|
I have this hierarchy:
<class name="ie.simtel.jazz.dto.Artist" table="ARTIST">
..
<set name="albums" inverse="true">
<key column="ARTIST_ID" />
<one-to-many class="ie.simtel.jazz.dto.Album" />
</set>
</class>
<class name="ie.simtel.jazz.dto.Album" table="ALBUMS">
..
<many-to-one name="artista" class="ie.simtel.jazz.dto.Artist" column="ARTIST_ID" />
</class>
And I need a list of albums with the associate artist ordered by name of the artist (1) or by title of the album (2):
(1)list = sess.createQuery("from Album as album order by album.artist.name").list();
(2)list = sess.createQuery("from Album as album order by album.title").list();
It works well, but I think Hibernate uses a select more than expected:
select all albums (ok)
for each album:
select the artist (ok)
for each artist:
select albums (why?)
The last group of select seems unnecessary. Hibernate has already
fetched all data of all albums with the first select, why does it query again the db? Is this behaviour by design?
Thank you
|
|