-->
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.  [ 4 posts ] 
Author Message
 Post subject: Join and Meta-data ?
PostPosted: Sun Feb 27, 2005 8:39 am 
Regular
Regular

Joined: Tue Jul 13, 2004 2:27 am
Posts: 73
Location: Singapore
I have a question - sorry of it is too application specific:

I am implementing some meta-data kind of thing in my application. Say I have one domain object D which canbe defined by a number of attribute groups, which in turn consists of a number of attributes.

so D <one-to-many> attribute groups <one-to-many> attributes

an attribute group simply has (name) and
an attribute has (name, value)

So here is the mappings:

domain object
----------------
<class name="D" ...>
......
<set name="attributeGroups" lazy="true" cascade="all-delete-orphan">
<key column="D_ID"/>
<one-to-many class="AttributeGroup"/>
</set>

</class>

attribute group
----------------
<class name="AttributeGroup" ...>
......
<set name="attributes" cascade="all-delete-orphan" lazy="true">
<key column="ATTRIBUTEGROUP_ID"/>
<one-to-many class="Attribute"/>
</set>

</class>

attribute
----------
<class name="Attribute" ...>
......
<property name="name" type="string" not-null="true" column="NAME"/>
<property name="value" type="string" not-null="false" column="VALUE"/>

</class>


So now I want to get a list of objects D with certain creteria. for example, when attribute.name=".." and attribute.value="...".

How can I use join to do this?

I can do this:
<b>
select d from D d join d.attributeGroups ag where ag.name="ag1"
</b>
this will return a list of Ds if there is an attributeGroup called 'ag1'.

but how to go down to the next level (attribute level) ?

this gives me error:
<b>
select d from D d join d.attributeGroups.attributes a where a.name="..."
</b>
thanks
li xin chu


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 27, 2005 10:14 pm 
Regular
Regular

Joined: Tue Jul 13, 2004 2:27 am
Posts: 73
Location: Singapore
the error that I am getting by running the second sql statement is:

1 errors occurred while listing (and calling getPathNames).
net.sf.hibernate.QueryException: expecting 'elements' or 'indices' after: attributes [select org from Org as org join org.attributeGroups.attributes attribute]


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 27, 2005 11:30 pm 
Regular
Regular

Joined: Tue Jul 13, 2004 2:27 am
Posts: 73
Location: Singapore
I can query with one condition now:

select d from D as d join d.attributeGroups as attributeGroup join attributeGroup.attributes as attribute where attribute.name="a2" and attribute.value="a2"

but what do I need to do so that I can check multiple conditions ? For example, to get the Ds if two attributes exists, one with name a1, value v1 and another with name a2, and value v2 ?

seems that i need to work on the attributes table directly....


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 01, 2005 2:24 am 
Regular
Regular

Joined: Tue Jul 13, 2004 2:27 am
Posts: 73
Location: Singapore
I can only think of using intersect (hence native sql) to handle multiple conditions like this.

any better idea ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.