title: Hibernate query: does a Set contains a certain Object?
body: <p>I have two Hibernate data object. The first is a User (with unique id, username etc.) and the second is the class Collaborateable. Between this two there is a n-to-m relation (implementet with Sets). That means, a User works on many Collaborateables and a Collaborateable has many users. In addition a Collaborateable has exactly one User as owner.</p>
  
  <pre><code>&lt;class name="CollaborateableImpl" table="Collaborateable"&gt;
  &lt;id name="id" type="int" column="id"&gt;
      &lt;generator class="increment" /&gt;
  &lt;/id&gt;
  
  &lt;property name="name" column="name" type="string" not-null="true" /&gt;
  &lt;property name="keywords" column="keywords" type="string"/&gt;
  
  &lt;!-- Collaborateable has a Registered User as owner --&gt;
  &lt;many-to-one name="owner" class="UserImpl" fetch="select"&gt;
          &lt;column name="User_id_owner" not-null="true" /&gt;
  &lt;/many-to-one&gt;
  
  &lt;!-- Users that collaborate on this Collaborateable --&gt;
  &lt;set name="users" table="CollaborateOn" inverse="false"&gt;        
          &lt;key column="Collaborateable_id" /&gt;         
          &lt;many-to-many column="User_id" class="UserImpl" /&gt;    
  &lt;/set&gt;
  </code></pre>
  
  <p></p>
  
  <p>i would like to implement a Hibernate query, that searches for Collaborateables that have a certain user as owner OR containing the same certain User in the Collaborateable.users Set. In addition, there should also be a simple WHERE clause to check for Keywords.</p>
  
  <p>Is there something like a CONTAINS operator in Hibernate?</p>
  
  <p>For example:</p>
  
  <pre><code>FROM CollaborateableImpl WHERE (owner = :user OR users CONTAINS :user) AND keywords like '%:searchString%'
  </code></pre>
  
  <p>Otherwise, do you know how to solve this problem with a join?</p>