title: Hibernate criteria: search by content on a property list in an entity
body: <p>I want to search by content on a property in an entity</p>
  
  <p>I have a simple class to define a User:</p>
  
  <pre><code>@Entity
  public class User {
  
      @Id
      @Column(name = "pers_id")
      private int persId; 
  
      @Column(name = "full_name")
      private String fullName;    
  
      @OneToMany
      @JoinColumn(name = "PERS_ID")
      private List&lt;UserLanguages&gt; languages = new ArrayList&lt;UserLanguages&gt;();
  }
  </code></pre>
  
  <p>A User can have multiple languages, here is the class to make the link between user and a language.</p>
  
  <pre><code>@Entity
  public class UserLanguages {
      @Column(name="pers_id")
      private int persId; 
  
      @Id
      @Column(name="lang_iso_code")
      private String langISO;
  
      @Column(name="lang_full_name")
      private String langFullName;
  
      @Column(name="order_seq")
      private int order;
  }
  
  @Entity
  public class Language {
      @Id 
      @Column(name="ID")
      private long id;
  
      @Column(name = "CODE")  
      private String code;
  }
  </code></pre>
  
  <p>I have created a object to do search:</p>
  
  <pre><code>public class UserFilter {    
      private String name;
  
      private List&lt;Language&gt; languages;
  }
  </code></pre>
  
  <p>I have defined a service:</p>
  
  <pre><code>@Service("userService")
  public class UserServiceImpl implements UserService {
  
  @Override
  public List&lt;User&gt; findByFilter(UserFilter userFilter) {
      final Criteria criteria = userDao.createCriteria();
      if (userFilter.getName() != null) {
          for (final String token : userFilter.getName().toLowerCase().trim().split(" ")) {
          criteria.add(Restrictions.like("fullName", "%" + token + "%"));
          }
      }
  
      if (null != userFilter.getLanguages() &amp;&amp; userFilter.getLanguages().size() &gt; 0) {
  
          final List&lt;String&gt; contents = new ArrayList&lt;String&gt;(userFilter.getLanguages().size());
          for (final Language lang : userFilter.getLanguages()) {
          contents.add(lang.getCode());
          }    
          criteria.add(Restrictions.in("languages", contents));
      }
  
      return userDao.findByCriteria(criteria);
  }
  </code></pre>
  
  <p>My question is how can I do search on languages. I want to find all users with this or thoses languages defined in the userFilter param.
  The part about languages doesn't work in the method findByFilter in the service. Can you help me?</p>