views:

288

answers:

0

Hi,

I have two entities: "Parent" & "Child"

Child is mapped in Parent like this:

Code:

 <many-to-one name="child" class="org.demo.Child"
     update="false" insert="false" embed-xml="false" node="chd/@id" >
     <column name="CHILD_ID" precision="10" scale="0"   not-null="true" />
  </many-to-one>

and Child has an Enum type mapped like this:

Code:

<property name="toyType">
     <column name="TOY_TYPE" length="100" />
     <type name="org.demo.type.LabelEnumType">
        <param name="enum">org.demo.ToyType</param>
        <param name="defaultLabel"></param>
     </type>
  </property>

mapped as a "String" in CHILD.TOY_TYPE column

Everything works fine but I cannot do this:

Code:

  DetachedCriteria dc = DetachedCriteria.forClass(Parent.class);
  dc.add(Restrictions.and(
           Restrictions.eq("child.id", childId),
           Restrictions.eq("child.toyType", ToyType.CAR)));
  dc.setProjection(Projections.rowCount());
  int count = DataAccessUtils.intResult(getHibernateTemplate().findByCriteria(dc));

because I got:

nested exception is org.hibernate.QueryException: could not resolve property: child.toyType of: org.demo.Parent

so it looks like it cannot solve:

parent->child->toyType

probably because ToyType has not an own "Entity", but it is embedded.

Is there any workaround for it? I need to continue using DetachedCriteria as it will be "decorated" in other places of the code. So I'm wondering if I can solve that always using DetachedCriteria.

Thanks, Rand