-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: HQL for criteria involving classes inside Map
PostPosted: Thu May 05, 2005 3:57 pm 
Newbie

Joined: Mon Mar 15, 2004 4:59 pm
Posts: 3
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:


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.