-->
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.  [ 2 posts ] 
Author Message
 Post subject: Querying for an object based on a property in a set...
PostPosted: Mon Sep 10, 2007 1:25 pm 
Newbie

Joined: Tue Jun 12, 2007 11:16 am
Posts: 5
I'm trying to query for an object, matching a value of a property in a set that holds composite elements:

Code:
<class name="link" table="linkstable">
   <id name="id" column="ID">
      <generator class="native" />
   </id>
   <set name="UIDS" table="uidstable">
      <key column="lid" not-null="true"/>
      <composite-element class="uidclass">
         <property name="uid"/> <!-- string -->
         <property name="someprop1"/>
         <property name="someprop2"/>
      </composite-element>
   </set>
</class>


And link class looking like:
Code:
class link
{
  private Integer id;
  private Set uids = new HashSet();  // set of uidclass
  // ctor snipped
  // plain jane getter and setters snipped
}

class uidclass
{
  private String uid;
  private boolean someprop1;
  private boolean someprop2;
  // ctor and plain jane getters and setters snipped.
}


The only query string that I can come up with (but doesn't work) is:

Code:
from link as link where :uid in elements(link.UIDS.UID)


I get a:

Quote:
org.hibernate.QueryException: illegal attempt to dereference collection [hibernatet0_.ID.UIDS] with element property reference [UID] [from link as link where :uid in elements(link.UIDS.UID)]


If I were using plain sql, a simplistic query could be something like:
Code:
select * from links, uids where links.id = uids.lid and uids.uid = "searchvalue"


So, my question is: is "in elements()" the right way to search on the value of a property in a set? If not, how?

Searching the uids table and then selecting the link object by id seems like one way, but wouldn't that prevent me from having several conditions in the set? (ie. where :uid1 in elements(link.UIDS.UID) and :uid2 in elements(link.UIDS.UID))


Using hibernate 3.2.4, Mysql 5.0.

-Trevor


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 10, 2007 3:50 pm 
Newbie

Joined: Tue Jun 12, 2007 11:16 am
Posts: 5
feel a little silly replying to my own post with an answer, but some more google foo turned up this buried in the faq/tips and tricks:

Quote:
from MyClass mc join mc.relationship r


Which in my case, I turned into:

Code:
from Link as link join link.UIDS as uid where uid.UID = :uid


(please forgive the excessive repetion of 'uid'. I guess I should be a little more creative with my class/property names)

Seems to work just fine.

Thanks me!


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