What am I doing wrong that following query:
Code:
List list = session.find("select parent from Parent parent left outer join parent.children");
cause so many selects:
Hibernate: select parent0_.bbb_id as bbb_id, parent0_.bbb_name as bbb_name from deploy.dbo.bbb parent0_ left outer join deploy.dbo.aaa children1_ on parent0_.bbb_id=children1_.aaa_bbb_id
Hibernate: select aaa0_.aaa_id as aaa_id__, aaa0_.aaa_id as aaa_id, aaa0_.aaa_bbb_id as aaa_bbb_id from deploy.dbo.aaa aaa0_ where aaa0_.aaa_bbb_id=?
Hibernate: select aaa0_.aaa_id as aaa_id__, aaa0_.aaa_id as aaa_id, aaa0_.aaa_bbb_id as aaa_bbb_id from deploy.dbo.aaa aaa0_ where aaa0_.aaa_bbb_id=?
Hibernate: select aaa0_.aaa_id as aaa_id__, aaa0_.aaa_id as aaa_id, aaa0_.aaa_bbb_id as aaa_bbb_id from deploy.dbo.aaa aaa0_ where aaa0_.aaa_bbb_id=?etc.
How can I force Hibernate to do it in one retrieve Parents with Children in using one select.
My configuration looks like this:
1.It's classical case [Parent]<1---*>[Child].
2.Collection of children is not lazy initialized (lazy="false").
3.Hibernate 2.0.3.
4.Mapping and configuration files like below.
Code:
<hibernate-mapping>
<class
name="iqa.appl.deployment.info.Parent"
table="deploy.dbo.bbb"
>
<id
name="id"
column="bbb_id"
type="int"
>
<generator class="identity">
</generator>
</id>
<property
name="name"
type="java.lang.String"
column="bbb_name"
/>
<set
name="children"
lazy="false"
inverse="false"
cascade="none"
sort="unsorted"
>
<key
column="aaa_bbb_id"
/>
<one-to-many
class="iqa.appl.deployment.info.Child"
/>
</set>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class
name="iqa.appl.deployment.info.Child"
table="deploy.dbo.aaa"
>
<id
name="id"
column="aaa_id"
type="int"
>
<generator class="identity">
</generator>
</id>
<many-to-one
name="parent"
class="iqa.appl.deployment.info.Parent"
cascade="none"
outer-join="auto"
column="aaa_bbb_id"
/>
</class>
</hibernate-mapping>
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">net.sf.hibernate.dialect.SybaseDialect</property>
<property name="hibernate.connection.driver_class">com.jnetdirect.jsql.JSQLDriver</property>
<property name="hibernate.connection.url">jdbc:JSQLConnect://myserver:1268/database=family/logfile=jsql.log</property>
<property name="hibernate.connection.username">mi</property>
<property name="hibernate.connection.password">mi</property>
<property name="hibernate.connection.pool_size">1</property>
<property name="hibernate.statement_cache.size">25</property>
<property name="hibernate.jdbc.batch_size">0</property>
<property name="hibernate.jdbc.use_streams_for_binary">true</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.use_outer_join">true</property>
<mapping resource="Child.hbm.xml"/>
<mapping resource="Parent.hbm.xml"/>
</session-factory>
</hibernate-configuration>