I have a POJO Person, with a Map called metaData which contains information about this Person. The map is keyed by a class MetaData and has a value of null if the data is self-describing (eg: Senior-citizen) or a value of MetaDataValue class if it requires something (eg: age-> 50, birthplace->US). MetaDataValue is used because the value can either be an int or string (as shown before).
MetaData class has the fields id, name, and value (for the senior citizen eg it would be name='type' value='senior', and someone else may be name='type', value='kid').
MetaDataValue class is an inheritance object which has two implementations, one is MetaDataValueString and the other is MetaDataValueFloat.
Now here is the question. I am trying to write an HQL query to fnd all people between a certain age and (born in a certain city or type is senior). The actual values are too far abstracted out.
I'm looking for either HQL to help me or a better way to do this. The reason I am using the MetaData is because I want to predefine certain fields: eg: the type field can only be senior, adult, or kid. But other fields, such as age, can have a value. I'd really like to keep this inside one map if possible.
Hibernate version: 2.1.7
Mapping documents:
Code:
<class
name="eg.Person"
table="eg_person"
dynamic-update="false"
dynamic-insert="false"
select-before-update="false"
optimistic-lock="version"
>
<id
name="personId"
column="personId"
type="java.lang.Long"
>
<generator class="native"/>
</id>
<map
name="metaData"
table="person_metadata"
lazy="true"
sort="unsorted"
inverse="false"
cascade="all"
>
<key
column="personId_fk"
>
</key>
<index-many-to-many
class="eg.MetaData"
column="metaDataId_fk"
/>
<one-to-many
class="eg.MetaDataValue"
/>
</map>
</class>
<class
name="eg.MetaData"
table="metadata"
dynamic-update="false"
dynamic-insert="false"
select-before-update="false"
optimistic-lock="version"
>
<id
name="metaDataId"
column="metaDataId"
type="java.lang.Long"
>
<generator class="native"/>
</id>
<property
name="metaName"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="metaName"
not-null="true"
/>
<property
name="metaValue"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="metaValue"
/>
</class>
<class
name="eg.MetaDataValue"
table="eg_metadatavalue"
dynamic-update="false"
dynamic-insert="false"
select-before-update="false"
optimistic-lock="version"
discriminator-value="0"
>
<id
name="metaDataValueId"
column="metaDataValueId"
type="java.lang.Long"
>
<generator class="native"/>
</id>
<discriminator
column="dataType"
type="integer"
/>
<subclass
name="eg.MetaDataValueFloat"
dynamic-update="false"
dynamic-insert="false"
discriminator-value="1"
>
<property
name="metaDataValueFloat"
type="java.lang.Float"
update="true"
insert="true"
access="property"
column="metaDataValueFloat"
/>
</subclass>
<subclass
name="eg.MetaDataValueString"
dynamic-update="false"
dynamic-insert="false"
discriminator-value="2"
>
<property
name="metaDataValueString"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="metaDataValueString"
/>
</subclass>
</class>
Name and version of the database you are using: MySql 4.1 with subselects
Code: