title: Spring JPA Hibernate how to find array column contains certain elements Named Query
body: <p>Suppose I have an entity</p>
  
  <pre><code>@Entity
  public class Course{
      @Id
      private Long id;
  
      private String courseName;
  
      //getter and setters
  }
  </code></pre>
  
  <p>now I want to find a <code>Course</code> by its <code>name</code>, hence in its repository, I put a named query,</p>
  
  <pre><code>public interface CourseRepository extends JpaRepository&lt;Course, Long&gt; {
  
      @Query(value = "SELECT * FROM course c where c.name = :name", nativeQuery=true)
      List&lt;Course&gt; findByName(@Param("name") String name);
  
  }
  </code></pre>
  
  <p>Now lets say <code>Course</code> entity gets a <code>String[]</code> column which will contain the name of days the course class supposed to be held. So the entity becomes</p>
  
  <pre><code>@Entity
  public class Course{
      @Id
      private Long id;
  
      private String courseName;
  
      //will contain {"Tue", "Wed", "Thr"} etc ... the class days
      private String [] classDays; 
  
      //getter and setters
  }
  </code></pre>
  
  <p><strong>Now I want to find the Courses that are held in Thr.</strong> How do I write a named query for that ? I have something like this in mind </p>
  
  <pre><code>SELECT * FROM course c where :day in c.class_days
  </code></pre>
  
  <p>but will that work ?</p>