title: Invalid PathExpression must be a StateFieldPathExpression
body: <p>I am currently working in a project using Symfony3.4, a project is about booking rooms of an hotel.<br>
  I have two entities <code>room(id,...)</code> and <code>bookings(room,check_in,check_out,...)</code> and the relation between them is <code>OneToMany</code>.<br>
  I am trying to retrieve rooms that are not booked by <code>check_in</code> and <code>check_out</code> fields.<br>
  I did a function in <code>RoomRepository</code> called <code>findRoomsNotBookedByCheckInCheckOut</code>  </p>
  
  <pre><code>public function findRoomsNotBookedByCheckInCheckOut(Request $request) {
          $em = $this-&gt;getEntityManager();
  
          $q = $em-&gt;createQuery("SELECT r FROM AppBundle:Room r "
          . "WHERE r NOT IN ( "
          . "SELECT b.room FROM AppBundle:Bookings b "
          . "WHERE NOT ( "
          . "b.checkOut &lt;= :checkIn "
          . "OR b.checkIn &gt;= :checkOut "
          . ") "
          . ") ORDER BY r.id")
          -&gt;setParameter('checkIn', "'".$request-&gt;query-&gt;get('check-out')."'")
          -&gt;setParameter('checkOut', "'".$request-&gt;query-&gt;get('check-in')."'");
  
          die($q-&gt;getSQL());
          return $q-&gt;getResult();
      }  
  </code></pre>
  
  <p>When I call this function from the controller  </p>
  
  <pre><code>private function roomsByCheckInCheckOut(Request $request, $em) {
          if ($request-&gt;query-&gt;get('check-in') != null &amp;&amp; $request-&gt;query-&gt;get('check-out') != null) {
  
             $rooms = $em-&gt;getRepository('AppBundle:Room')-&gt;findRoomsNotBookedByCheckInCheckOut($request);
  
          }
          return null;
      }  
  </code></pre>
  
  <p>I get an error which is :</p>
  
  <pre><code>[Semantical Error] line 0, col 57 near 'room FROM AppBundle:Bookings': Error: Invalid PathExpression. Must be a StateFieldPathExpression.  
  </code></pre>
  
  <p>I tried to fixed by change the <code>b.room</code> to <code>b.room.id</code> : </p>
  
  <pre><code>public function findRoomsNotBookedByCheckInCheckOut(Request $request) {
          $em = $this-&gt;getEntityManager();
  
          $q = $em-&gt;createQuery("SELECT r FROM AppBundle:Room r "
          . "WHERE r NOT IN ( "
          . "SELECT b.room.id FROM AppBundle:Bookings b "
          . "WHERE NOT ( "
          . "b.checkOut &lt;= :checkIn "
          . "OR b.checkIn &gt;= :checkOut "
          . ") "
          . ") ORDER BY r.id")
          -&gt;setParameter('checkIn', "'".$request-&gt;query-&gt;get('check-out')."'")
          -&gt;setParameter('checkOut', "'".$request-&gt;query-&gt;get('check-in')."'");
  
          die($q-&gt;getSQL());
          return $q-&gt;getResult();
      }
  </code></pre>
  
  <p>and I get another error which is :</p>
  
  <pre><code>[Semantical Error] line 0, col 62 near 'id FROM AppBundle:Bookings': Error: Class AppBundle\Entity\Bookings has no field or association named room.id
  </code></pre>
  
  <p>which is logic because the entity <code>bookings</code> does not have a <code>room.id</code> but it has <code>room</code>.<br>
  I tried again to solve by changing <code>b.room</code> to <code>b</code> and the function become : </p>
  
  <pre><code>public function findRoomsNotBookedByCheckInCheckOut(Request $request) {
          $em = $this-&gt;getEntityManager();
  
          $q = $em-&gt;createQuery("SELECT r FROM AppBundle:Room r "
          . "WHERE r NOT IN ( "
          . "SELECT b FROM AppBundle:Bookings b "
          . "WHERE NOT ( "
          . "b.checkOut &lt;= :checkIn "
          . "OR b.checkIn &gt;= :checkOut "
          . ") "
          . ") ORDER BY r.id")
          -&gt;setParameter('checkIn', "'".$request-&gt;query-&gt;get('check-out')."'")
          -&gt;setParameter('checkOut', "'".$request-&gt;query-&gt;get('check-in')."'");
  
          die($q-&gt;getSQL());
          return $q-&gt;getResult();
      }
  </code></pre>
  
  <p>it worked fine without any error but it didn't retrieve the right result.<br>
  <strong>note: I tested the sql query in MySQL database and I get the right result</strong>  </p>