-->
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.  [ 1 post ] 
Author Message
 Post subject: How to set the resultset size
PostPosted: Wed Mar 05, 2008 4:00 pm 
Newbie

Joined: Tue Apr 25, 2006 1:17 pm
Posts: 19
How can I set the number of items are returned back from an associated collection fetch when the parent object is retrieved with session.get or session.load?

I have a class called Album which contains an association to Artists (via one-to-many using a linking table) and some albums will have 20+ artists. When I retrieve it with 'album.getArtists' (where album was loaded with a session.get by album id), the SQL statements I see are broken up into multiple SELECTs on the Artist table with the number of items set to be retrieved varying between 10 (when there are 14 total artists) and 16 (when there are 29 artists).

The SQL statement generated looks like:
select artist0_.ID as ID6_0,
artists0_.Name as Name6_0
from Artist artist0_
where artist0_.ID in (?, ?, ?, ..)

For the album with 14 artists, I don't understand why all 14 would be returned with two SELECTs from Artists instead of one SELECT with the first asking for 10 items and the 2nd one with 4 items. For the one with 29 items, I see three queries with resultset sizes of 16, 10, and 2 respectively.

Is there a property that can be set to to return atleast a certain number of items in the result set so that atleast the one with 14 items will only take up 1 query instead of 2?

I have the following properties set in my hibernate configuration:

<property name="default_batch_fetch_size">16</property>
<property name="jdbc.fetch_size">32</property>
<property name="jdbc.batch_size">5</property>

There is a linking table between Album and Artist called AlbumArtistLink so full mapping relation ship is outlined as below:
<hibernate-mapping >
<class name="Album" table="Album" dynamic-update="true">
<id name="id" type="int">
<column name="ID" />
<generator class="identity"/>
</id>
<property name="name" type="string">
<column name="Name" length="128" not-null="true">
<comment></comment>
</column>
</property>
<set name="albumArtist" inverse="true" cascade="all, delete-orphan" lazy="true">
<key>
<column name="AlbumID" not-null="true">
<comment></comment>
</column>
</key>
<one-to-many class="AlbumArtist" />
</set>
</class>

<class name="AlbumArtist" table="AlbumArtistLink" dynamic-update="true">
<composite-id name="id" class="AlbumArtistId">
<key-property name="albumId" type="int">
<column name="AlbumID" />
</key-property>
<key-property name="artistId" type="int">
<column name="ArtistID" />
</key-property>
</composite-id>
<many-to-one name="album" class="Album" update="false" insert="false" fetch="select">
<column name="AlbumID" not-null="true">
<comment></comment>
</column>
</many-to-one>
<many-to-one name="artist" class="Artist" update="false" insert="false" fetch="select" lazy="proxy">
<column name="ArtistID" not-null="true">
<comment></comment>
</column>
</many-to-one>
<property name="role" type="byte">
<column name="Role" not-null="true"/>
</property>
</class>
</hibernate-mapping>

Thanks,
Justin


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

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.