Help me, please!
mapping:
<hibernate-mapping
package="hb3">
<class name="ClientM1" table="Clients" lazy="true">
<id name="id" type="long">
<generator class="native"/>
</id>
<property name="name" type="string" length="30" />
<set name="phonesset">
<key column="client_id"/>
<one-to-many class="Phone"/>
</set>
</class>
<class name="Phone">
<id name="idphone">
<generator class="native"/>
</id>
<property name="Phone" type="string"/>
<property name="Ph_type" type="short"/>
</class>
</hibernate-mapping>
now - a insert 1 record in ClassM1 table and 10001 records in Phone table
next - im try get my recors manualy - by 1 per cicle. but!:
long id=1;
ClientM1 c1= (ClientM1) session.load(ClientM1.class,new Long(id));
Phone ph1;
for(Iterator tt=c1.getPhonesset().iterator(); tt.hasNext();)
{
/* select clientm1x0_.id as id0_, clientm1x0_.name as name0_0_ from Clients clientm1x0_ where clientm1x0_.id=? */
/* select phonesset0_.client_id as client4_1_, phonesset0_.idphone as idphone1_, phonesset0_.idphone as idphone0_, phonesset0_.Phone as Phone1_0_, phonesset0_.Ph_type as Ph3_1_0_ from Phone phonesset0_ where phonesset0_.client_id=? */
/*
in this statement hibernate read all set - (fetch all records from Phone)
by use opened second select
*/
/* on this poin - all record already rean into Set */
ph1=(Phone)tt.next();
System.out.println(ph1.getPhone());
System.out.println(c1.getPhonesset().size());
/* output -10001 */
}
But im need fetch 1 record by 1 cycle.
How do it?
Thsnks!
PS: use
<set name="phonesset" lazy="false" fetch="select" >
<key column="client_id" />
<one-to-many class="Phone"/>
</set>
with fetch= any right value ("select, subselect and join)
and
<property name="hibernate.max_fetch_depth">2</property>
<property name="hibernate.default_batch_fetch_size">4</property>
<property name="hibernate.jdbc.fetch_size">10</property>
dont have effect ....
|