-->
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.  [ 3 posts ] 
Author Message
 Post subject: HQL with "map" collection of values
PostPosted: Thu May 10, 2007 3:52 pm 
Beginner
Beginner

Joined: Mon Nov 07, 2005 11:06 pm
Posts: 28
Given the following mapping file...

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
    <class name="Infosnap.Serenity.Domain.RosterEntry, Infosnap.Serenity.Domain" table="RosterEntries" lazy="false">
        <id name="ID" column="ID" type="Int32" unsaved-value="0">
            <generator class="identity" />
        </id>
        <property name="ActionID" column="ActionID" type="Int32" />
        <property name="ExternalStudentID" column="ExternalStudentID" type="String" length="25" />
        <property name="StudentFirstName" column="StudentFirstName" type="String" length="25" />
        <property name="StudentLastName" column="StudentLastName" type="String" length="25" />
        <property name="ExternalFamilyID" column="ExternalFamilyID" type="String" length="25" />
        <property name="FamilyEmailAddress" column="FamilyEmailAddress" type="String" length="100" />
        <property name="Tags" column="Tags" type="String" length="100" />
        <many-to-one name="Invitation" class="Infosnap.Serenity.Domain.Invitation, Infosnap.Serenity.Domain"
                     column="InvitationID" cascade="all" unique="true" />
        <map name="DataValues" table="RosterData" access="nosetter.camelcase-underscore" lazy="true">
            <key column="RosterEntryID"/>
            <index column="FieldName" type="String" length="50" />
            <element column="FieldValue" type="String" length="4000" />
        </map>
    </class>
</hibernate-mapping>


I want to construct a query similar to the following SQL...

Code:
select a.*
from RosterEntries a
join RosterData b on a.ID = b.RosterEntryID
where b.FieldName = 'MyFieldName'
and b.FieldValue = 'SomeFieldValue'


Therefore, if "MyFieldName" does not exist, or if it does and the associated FieldValue does not equal "SomeFieldValue", then I do not want the record returned.

Conceptually, I want to do something like this...

Code:
from RosterEntry entry
where entry.DataValues['MyFieldName'] = 'SomeFieldValue'

But, I am not sure if this approach is even supported.

I have seen some examples where you can do this IF the map is a map of entities, but I have a simple map of strings. Basically, the DataValues map is a string dictionary in .Net.

Does anyone know how to do this? Thanks in advance!

Kevin


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 10, 2007 5:45 pm 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
How about
Code:
FROM  RosterEntry
JOIN  RosterEntry.DataValues AS RosterData
WHERE RosterData.FieldName  = :fieldName
AND   RosterData.FieldValue = :fieldValue


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 11, 2007 4:21 am 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
Actually I think Nels may have missed that DataValues is a map, so you might have trouble with the where clause. Try this:

Code:
FROM  RosterEntry
JOIN  RosterEntry.DataValues AS RosterData
WHERE INDEX(RosterData) = :fieldName
AND RosterData = :fieldValue


Obvisouly untested, but I think it's right...

Symon.


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

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.