I've been trying different ways to do this, but just can't seem to figure it out. I have two different objects, represented in this way ...
Parent - FoodGrpLst
Child - FoodSubGrpLst
The mapping files for these classes is as follows..
for FoodGrpLst...
<class name="webapp.lists.FoodGrpLst" table="FOOD_GROUPS" mutable="false"> <id name="foodGroupID" column="FOOD_GROUP_ID"> <generator class="native"/> </id> <property name="foodGroupNameE" column="FOOD_GROUP_EN_NAME"/> <property name="foodGroupNameF" column="FOOD_GROUP_FR_NAME"/> </class>
for FoodSubGrpLst...
<class name="webapp.lists.FoodSubGrpLst" table="FOOD_SUBGROUPS" mutable="false"> <id name="foodSubgroupID" column="FOOD_SUBGROUP_ID"> <generator class="native"/> </id> <property name="foodSubgroupNameE" column="FOOD_SUBGROUP_EN_NAME"/> <property name="foodSubgroupNameF" column="FOOD_SUBGROUP_FR_NAME"/>
<many-to-one name="foodGroup" class="webapp.lists.FoodGrpLst" column="FOOD_GROUP_ID" cascade="none"/> </class>
The class parameter declarations for FoodSubGrpLst starts off like this ..
public class FoodSubGrpLst { private Long foodSubgroupID; private String foodSubgroupNameE; private String foodSubgroupNameF; private FoodGrpLst foodGroup = new FoodGrpLst(); private Long foodGroupID; . . . }
In my DAO for FoodSubGrp i would like to retrieve a collection of FoodSubGrp's based on a FoodGrp ID.
The method for this looks like this ...
public Collection getFoodSubGroupsbyFoodGroupID(Long foodGroupID, boolean lock) throws DBException {
Session session = HibernateUtil.getSession(); FoodSubGrpLst foodSubgroup = null; Collection foodSubgroupList = null;
try { Criteria crit = HibernateUtil.getSession().createCriteria FoodSubGrpLst.class); crit.add(Expression.eq("foodGroup", foodGroupID)); foodSubgroupList = crit.list(); } catch (HibernateException ex) { } return foodSubgroupList; }
On the line crit.add(Expression.eq("foodGroup", foodGroupID)); is where the problem is. "foodGroup" is the parameter in my mapping file that maps to the foreign key FOOD_GROUP_ID, however in my FoodSubGrpLst object it is represented as an object ...so I am thinking this is causing some problems. Anyone know a correct way to do what I'm trying to do?
Any help would be appreciated,
Thanks
|