I am trying to create a criteria that will take data across 4 tables. The hibernate classes linked to the tables and their variables linked to the columns are.
Alpha ala alb beid <
Beta bea id < gammaid<
Gamma gaa gab id< deltaid<
Delta dea deb id<
The < mark the primary/ forign keys
I can manage to get data across 3 tables, the code below takes the value ala from Alpha, bea from Beta and gab from Gamma where Gamma gaa equals the value of variableVal. The code below works ok for this. Alpha and gamma have lower case letters because inside the Beta class they are given lower case letters.
Criteria criteria2 = session.createCriteria(Beta.class,”be”) .createAlias(“alpha”,”al”) .createAlias(“gamma”,”ga”) .setProjection(projections.projecctionList() .add(Projections.property(“al.ala”)) .add(Projections.property(“be.bea”)) .add(Projections.property(“ga.gaa”)) ) .add(Restrictions.eq(“ga.gab”,varibleVal));
Now I want to get values across 4 tables. To take the value ala from Alpha, bea from Beta, gaa from Gamma and dea from delta where Gamma gab equals the value of variableVal and Delta dea equals the value variableVal2. I thought that I could add the extra alias and the new projection and restriction as below but this does not work. Hope my question is clear. Thanks for any help regarding this. Criteria criteria2 = session.createCriteria(Beta.class,”be”) .createAlias(“alpha”,”al”) .createAlias(“gamma”,”ga”) .createAlias(“delta”,”de”) .setProjection(projections.projectionList() .add(Projections.property(“al.ala”)) .add(Projections.property(“be.bea”)) .add(Projections.property(“ga.gab”)) .add(Projections.property(“de.dea”)) ) .add(Restrictions.eq(“ga.gab”,varibleVal)) .add(Restrictions.eq(“de.dea”,varibleVal2)); .
|