2009-07-01 2 views
3

다음과 같은 최대 절전 모드 매핑이 있습니다.최대 절전 모드에서지도 요소를 쿼리하는 방법?

<hibernate-mapping> 
    <class name="MutableEvent" table="events" 
     mutable="true" dynamic-insert="true" dynamic-update="true"> 

     <id name="id"> 
      <generator class="assigned" /> 
     </id> 
     <property name="sourceTimestamp" /> 
     <property name="entryTimestamp" /> 

     <map name="attributes" table="event_attribs" 
      access="field" cascade="all"> 
      <key column="id" /> 
      <map-key type="string" column="key" /> 
      <element type="VariantHibernateType"> 
       <column name="value_type" not-null="false" /> 
       <column name="value_string" not-null="false" /> 
       <column name="value_integer" not-null="false" /> 
       <column name="value_double" not-null="false" /> 
      </element> 
     </map> 

    </class> 
</hibernate-mapping> 

저장 및 내 개체 로딩 잘 작동합니다. 내가 가지고있는 질문은 지원되는 최대 절전 모드에서지도를 쿼리하고 있으며, 기준 API를 사용하여 어떻게 수행 할 것인가?

중요한 부분은 "속성을 확인할 수 없습니다 : attributes.other"로 실패합니다.

(이 부분은 실제로 내 테스트 사례의 일부입니다)
crit.add(Restrictions.eq("attributes.other", new Variant("aValue"))); 
List l = this.findByCriteria(crit); 

그 문제에 대한 해결책이 있습니까?

업데이트

List l = find("from MutableEvent M where M.attributes['other'] = ?", new Variant("aValue")); 

위의 코드는 예외를 throw하지 않지만 쿼리 자체는 여전히 원하는 것입니다. 내가 매핑에 의해 볼 수있는 사용자 정의 유형을 만들었습니다. 실제로 문자열 (value_string 열)을 쿼리하려고하지만 MutableEvent M에서 ""과 같은 유형의 일부에 액세스하기 위해 쿼리를 수정하려는 시도가있었습니다. 여기서 M은 attributes [ 'other']. 문자열 =? "가 작동하지 않습니다. 그렇다면 구성 요소의 일부를 어떻게 쿼리합니까?

형식은 다음과 같이 구현됩니다.

... 
private static final String[] PROPERTY_NAMES = { "type", "string", "integer", "double" }; 

public String[] getPropertyNames() { 
    return PROPERTY_NAMES; 
} 
... 
+2

Criteria API는 HQL만큼 강력하지 않으므로 HQL에서 map을 쿼리 할 수 ​​있습니다. – IAdapter

답변

0

은 기준에 대한 별명을 작성하십시오.

criteria.createAlias("attributes", "as"); 
criteria.add(Restrictions.ilike("as.other", new Variant("aValue")); 
관련 문제