First of All thank you all,
and I guess the solution is very close by using Property.forName
but I still have some questions and problems?
How will I use the
Property.forName
my attempt was to use it as follows:
Code:
Criteria stepsTransferChoicesCriteria = this.getSession().createCriteria(StepTransferChoice.class)
.setFetchMode("fromStep", FetchMode.JOIN)
.setFetchMode("toStep", FetchMode.JOIN);
Criteria fromStepCriteria = stepsTransferChoicesCriteria.createCriteria("fromStep");
Criteria toStepCriteria = stepsTransferChoicesCriteria.createCriteria("toStep");
Line 01: // if the follwoing two lines commented still we have problem
Line 02: fromStepCriteria.add(Restrictions.idEq(procedureStepId));
Line 03: toStepCriteria.add(Restrictions.idEq(procedureStepId));
stepsTransferChoicesCriteria.add(Restrictions.or(Property.forName("id").in(fromStepCriteria.list()),
Property.forName("id").in(toStepCriteria.list())) );
I think I still miss-using the Property.forName
as with the existence of the three labeled lines 01, 02, 03
it generate the following query: Code:
select *
from STEP_TRANSFER_CHOICE this_ inner join PROCEDURE_STEP procedures2_ on this_.TO_STEP_FK=procedures2_.ID
inner join PROCEDURE_STEP procedures1_ on this_.FROM_STEP_FK=procedures1_.ID
where procedures1_.ID = ? and procedures2_.ID = ? and (this_.ID in () or this_.ID in ())
and by commenting them it generate the following query: Code:
select *
from STEP_TRANSFER_CHOICE this_ inner join PROCEDURE_STEP procedures2_ on this_.TO_STEP_FK=procedures2_.ID
inner join PROCEDURE_STEP procedures1_ on this_.FROM_STEP_FK=procedures1_.ID
where (this_.ID in (?, ?, ?, ?, ?, ?) or this_.ID in (?, ?, ?, ?, ?, ?))
which both queries is not correct.
I guess there should be some mean to refer to the id of the first Sub Criteria some alias.