-->
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: Query..ummm... query
PostPosted: Fri Feb 13, 2004 8:33 pm 
Beginner
Beginner

Joined: Mon Dec 29, 2003 12:49 pm
Posts: 41
Location: Boston, MA
Hello all,

I'm using MySQL 4.0.17 which doesn't support subselects. Given the following:

A.) I have a Users joined-subclass which contains a Set of PartyAttribute objects called partyAttributes that is inherited from its parent object, Party. This is mapped in the mapping file (in the Party declaration) as:
Code:
<set name="partyAttributes" inverse="true" lazy="false" outer-join="false" batch-size="30">
            <key column="PARTY_ID"/>
            <one-to-many class="org.wgbh.scape.domain.PartyAttribute"/>
</set>


B.) A PartyAttribute object contains (amongst other things) an ivar called attributeValue - this is just a string and looks like this in the mapping declaration for PartyAttribute:
Code:
<property name="attributeValue" column="ATTRIBUTE_VALUE" type="string">
            <meta attribute="finder">findByValue</meta>
</property>


C.) A PartyAttribute object also contains an instance variable of type PartyTypeDefinition mapped thusly:
Code:
<many-to-one name="attributeDefinition" column="ATTRIBUTE_ID" class="org.wgbh.scape.domain.PartyTypeDefinition" outer-join="false"/>


D.) A PartyTypeDefinition object contains a string attribute called attributeName mapped like this:
Code:

<property name="attributeName" column="ATTRIBUTE_NAME" type="string">
            <meta attribute="finder">findByAttributeName</meta>
</property>


E.) And the last 2 important things... Each user has another instance variable of type PartyType which is inherited fomr the Party superclass:
Code:
<many-to-one class="org.wgbh.scape.domain.PartyType" column="PARTY_TYPE_ID" name="partyType">
            <meta attribute="finder">findByPartyType</meta>
</many-to-one>


And this PartyType object in turn has a Set call definitions which maps to a Set of PartyTypeDefinition objects:
Code:
<set name="definitions" inverse="true" lazy="true" outer-join="false" batch-size="30">
            <key column="PARTY_TYPE_ID"/>
            <one-to-many class="org.wgbh.scape.domain.PartyTypeDefinition"/>
</set>


So the relationship between these class is such that a "Type" is defined to have x number of attributes via the PartyTypeDefinition. Domain objects (e.g. User objects) are then assigned a particular "type". The values associated with the attributes of this type are then associated with the object, thereby enabling the object to have its own set of unique values for the attributes required by the type. For example:

1.) A PartyType object is defined as having a name "Administrator"
2.) A PartyTypeDefinition object is then defined for the "Administrator" type. It has a single attributeName of "Title"
3.) A User object is created of Type "Administrator" and it defines the "Title" attribute as having a value of "System Administrator"

So, finally my question is, since MySQL doesn't support subselects, what kind of a query do I need to create (using HQL if possible) that will allow me to search the database for Users whose Title='System Administrator."

A User has a Set of partyAttributes based on its type. Each attribute has a value particular to that user, however the PartyTypeDefinition object itself has one or more values associated with it (e.g. the "Title" attribute is assigned more than one party and each party has a different value - i.e. PartyAttribute.value).

It kinda looks like this:

User.partyAttributes.attributeValue (partyAttribtutes is a set of all the PartyAttribute objects)
For PartyAttribute object x its name (on our example "Title") is x.attributeDefinition.attributeName

For a PartyType object called type:

type.definition.attributeName
type.definition.attributName.attributeValues (where attributeValues is a Set of all the values mapped to a particular attribute and definition is - currently - a Set of all the definitions for a type. Thinking about it now it should be a one-to-one instead of a one-to-many, but that's the way its mapped right now.)

Anyway...

- I had executed the following query:
Code:
select from org.wgbh.scape.domain.User as user, org.wgbh.scape.domain.PartyAttribute as pa where pa in elements(user.partyAttributes) and pa.attributeValue = 'Systems Developer'


Only to have it throw a JDBC exception for bad syntax. Is it possible to do what I want to do using MySQL? I know this is a rather convulted example, so I tried to be as explicit as possible. Hopefully an answer will be short (and in the affirmative vein). Thanks!

--Brian[/b]

_________________
Brian R. Wainwright
Systems Developer
WGBH Educational Foundation

"WGBH Boston informs, inspires, and entertains millions through public broadcasting, the Web, and educational multimedia, and access services for people with disabilities."


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2004 8:44 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Probably something like:

Code:
select user from org.wgbh.scape.domain.User as user left join user.partyAttributes as pa where pa.attributeValue = 'Systems Developer'


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 14, 2004 9:08 am 
Beginner
Beginner

Joined: Mon Dec 29, 2003 12:49 pm
Posts: 41
Location: Boston, MA
Thanks gloeglm. That works as easily as I had hoped.

_________________
Brian R. Wainwright
Systems Developer
WGBH Educational Foundation

"WGBH Boston informs, inspires, and entertains millions through public broadcasting, the Web, and educational multimedia, and access services for people with disabilities."


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.