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