1

「親」と「子」の2つのエンティティがあります

子は次のように親にマップされます。

コード:

 <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>

Child には次のようにマッピングされた Enum 型があります。

コード:

<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>

CHILD.TOY_TYPE列で「文字列」としてマップ

すべて正常に動作しますが、これを行うことはできません:

コード:

  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));

私が得たので:

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

解決できないようです:

parent->child->toyType

おそらく、ToyType には独自の「エンティティ」がありませんが、埋め込まれているためです。

回避策はありますか?コードの他の場所で「装飾」されるため、引き続き DetachedCriteria を使用する必要があります。ですから、常に DetachedCriteria を使用して解決できるかどうか疑問に思っています。

ありがとう、ランド

4

0 に答える 0