Hi,
I have an object with various attributes, and it in turn has several set collections mapped. I am trying to query a set of objects out based on both the object parameters and specific members of some collections. To show an example, I have a User and a Preference object defined as such (with extra data stripped for clarity):
Code:
<hibernate-mapping>
<class name="User" table="users">
<id column="userId" name="userId" length="64" unsaved-value="null">
<generator class="uuid.hex"/>
</id>
<property name="userName" unique="true" not-null="true" length="64"/>
<property name="firstName" unique="false" not-null="true" length="128"/>
<property name="lastName" unique="false" not-null="true" length="128"/>
<property name="password" unique="false" not-null="true" length="128"/>
<set name="preferences" lazy="false" inverse="true" cascade="all">
<key column="userId"/>
<one-to-many class="Preference"/>
</set>
</class>
</hibernate-mapping>
Code:
<hibernate-mapping>
<class name="Preference" table="user_preferences">
<id column="preferenceId" name="preferenceId" length="64" unsaved-value="null">
<generator class="uuid.hex"/>
</id>
<property name="name" unique="false" not-null="true" length="64"/>
<property name="value" unique="false" not-null="true" length="128"/>
<many-to-one name="user" column="userId" not-null="true"/>
</class>
</hibernate-mapping>
Now, I would like to do a query along the lines of:
Code:
from user in class User where user.firstName=:firstName and
user.preferences.name['receiveMail']=true
I know this isn't a valid query, but conceptually I would be selecting on both attributes of the User object as well as specific values of specific entries of the Preferences Set. In the example above, I would try using the Preference with the name "receiveMail" and its value would need to be true.
It looks like I need to do this through subqueries, but can anybody give pointers to how I would set this up?
thanks!