Hibernate version: 3.3.1
Name and version of the database you are using: Derby Embedded
<property name="show_sql">false</property>
<property name="format_sql">true</property>
<property name="use_outer_join">true</property>
<property name="hibernate.max_fetch_depth">5</property>
table XCPTN has two Many-To-One relationship with FIRM_REF and XCPTN_TYPE
if I run query this way:
Code:
Xcptn x = em.find(Xcptn.class, 1000L);
There is only ONE query:
Code:
select
xcptn0_.ID as ID0_2_,
xcptn0_.FIRM_ID as FIRM3_0_2_,
xcptn0_.MKT_CLS as MKT2_0_2_,
xcptn0_.TYPE_ID as TYPE4_0_2_,
firmref1_.ID as ID2_0_,
firmref1_.FIRM_MP_ID as FIRM2_2_0_,
xcptntype2_.ID as ID1_1_,
xcptntype2_.NAME as NAME1_1_
from
XCPTN xcptn0_
left outer join
FIRM_REF firmref1_
on xcptn0_.FIRM_ID=firmref1_.ID
left outer join
XCPTN_TYPE xcptntype2_
on xcptn0_.TYPE_ID=xcptntype2_.ID
where
xcptn0_.ID=?
But if I run it this way:
Code:
Query q = em.createQuery("from Xcptn x where x.id=1000");
There are three queries:
Code:
select
xcptn0_.ID as ID0_,
xcptn0_.FIRM_ID as FIRM3_0_,
xcptn0_.MKT_CLS as MKT2_0_,
xcptn0_.TYPE_ID as TYPE4_0_
from
XCPTN xcptn0_
where
xcptn0_.ID=1000
--------------------------
select
firmref0_.ID as ID2_0_,
firmref0_.FIRM_MP_ID as FIRM2_2_0_
from
FIRM_REF firmref0_
where
firmref0_.ID=?
-------------------------
select
xcptntype0_.ID as ID1_0_,
xcptntype0_.NAME as NAME1_0_
from
XCPTN_TYPE xcptntype0_
where
xcptntype0_.ID=?
How to force Hibernate to use one query with joins instead of three simple?