1

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

Gray
  • 115,027
  • 24
  • 293
  • 354
Randomize
  • 8,651
  • 18
  • 78
  • 133
  • The most obvious question would be, does you org.demo.Child dto have a reachable attribute toyType? – Matthew Flynn Apr 23 '10 at 18:20
  • Hi Matthew, What do u mean for "reachable attribute"? How can I check that? AFAIK enum item should be mapped on own table, tho I hope it's not really like that (I'm working on code by other people and this kind of situation is present in many parts). – Randomize Apr 24 '10 at 08:38

0 Answers0