Thursday, July 14, 2011

HQL with where clause on map values

HQL:
        "Select profileType from ProfileType profileType where profileType.profileProps['key'] = ?"
 
Mapping:
<hibernate-mapping default-cascade="delete" default-lazy="false">
 <class
  name="mypackage.ProfileType" table="PROFILETYPE">
  <id name="id" type="long" unsaved-value="0">
   <generator class="native"/>
  </id>
  <property generated="never" lazy="false" name="profileTypeName" type="java.lang.String">
   <column name="PROFILETYPENAME"/>
  </property>
  <map lazy="false" name="profileProps" sort="unsorted" table="PROFILEPROPS">
   <key>
    <column name="ID" unique="false"/>
   </key>
   <map-key type="java.lang.String">
    <column name="PROFILEPROPNAME" />
   </map-key>
   <element type="java.lang.String">
    <column name="PROFILEPROPVALUE"/>
   </element>
  </map>
 </class>
</hibernate-mapping>
public class ProfileType {
        @Id
        @GeneratedValue
        private long id;
        private String profileTypeName;
        private Map<String, String> profileProps;
…………
}

No comments:

Post a Comment