I have two objects, Program and Classification, with a one Program to many Classifications relationship.
Here is my criteria query:
Code:
Criteria crit2 = sessionFactory.getCurrentSession()
.createCriteria(Program.class)
.add(Restrictions.eq("code", input.getCode()))
.createAlias("classifications", "cl")
.add(Restrictions.eq("cl.id", 3249023L));
List<Program> programs2 = crit2.list();
and the SQL it generates has an additional left outer join which I cannot understand the purpose of?
Code:
Hibernate:
select
this_.id as id16_2_,
this_.created as created16_2_,
this_.modified as modified16_2_,
this_.version as version16_2_,
this_.active as active16_2_,
this_.adminProgramId as adminPro6_16_2_,
this_.code as code16_2_,
this_.deletable as deletable16_2_,
this_.desciption as desciption16_2_,
this_.discontinued as discont10_16_2_,
this_.effectiveDate as effecti11_16_2_,
this_.expirationDate as expirat12_16_2_,
this_.name as name16_2_,
this_.programVersion as program14_16_2_,
cl1_.id as id1_0_,
cl1_.created as created1_0_,
cl1_.modified as modified1_0_,
cl1_.version as version1_0_,
cl1_.causeOfLoss as causeOfL5_1_0_,
cl1_.code as code1_0_,
cl1_.description as descript7_1_0_,
cl1_.lobCode as lobCode1_0_,
cl1_.lobName as lobName1_0_,
cl1_.premiumBaseCode as premium10_1_0_,
cl1_.premiumBaseDesc as premium11_1_0_,
cl1_.premiumBaseValue as premium12_1_0_,
cl1_.program_id as program13_1_0_,
program4_.id as id16_1_,
program4_.created as created16_1_,
program4_.modified as modified16_1_,
program4_.version as version16_1_,
program4_.active as active16_1_,
program4_.adminProgramId as adminPro6_16_1_,
program4_.code as code16_1_,
program4_.deletable as deletable16_1_,
program4_.desciption as desciption16_1_,
program4_.discontinued as discont10_16_1_,
program4_.effectiveDate as effecti11_16_1_,
program4_.expirationDate as expirat12_16_1_,
program4_.name as name16_1_,
program4_.programVersion as program14_16_1_
from
Program this_
inner join
Classification cl1_
on this_.id=cl1_.program_id
left outer join
Program program4_
on cl1_.program_id=program4_.id
where
this_.code=?
and cl1_.id=?
Does anyone know why this block is there:
Code:
left outer join
Program program4_
on cl1_.program_id=program4_.id
how can I get rid of it as additional joins will impact performance.
thanks,
Peter