title: Spring data JPA using Entity Type expression
body: <p>I would like to use the JPA 2.0 Type expression in a spring data JPA repository <code>@Query</code> but it give me a validation error <code>Validation failed for query for method public abstract java.util.List my.org.FooRepository.findAllByRoomCode()!</code>.</p>
  
  <p>Here is my entities definition :</p>
  
  <p>inherited :</p>
  
  <pre><code>@Entity(name = "Location")
  @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
  public abstract class LocationEntity {
  
      @Column(name = "CODE")
      protected String code;
  
      @OneToMany(mappedBy = "location")
      protected List&lt;LampEntity&gt; lamps = new ArrayList&lt;LampEntity&gt;();
          ...
  }
  
  @Entity(name = "Floor")
  @Table(name = "FLOOR", uniqueConstraints = {
      @UniqueConstraint(name = "FLOOR_UK", columnNames = "CODE")
  })
  public class FloorEntity extends LocationEntity {
      ...
      @OneToMany(mappedBy = "floor")
      private List&lt;RoomEntity&gt; rooms = new ArrayList&lt;RoomEntity&gt;();
      ...
  }
  
  @Entity(name = "Room")
  @Table(name = "ROOM", uniqueConstraints = {
      @UniqueConstraint(name = "ROOM_UK", columnNames = { "CODE", "FLOOR_ID" })
  })
  public class RoomEntity extends LocationEntity {
      ...
      @ManyToOne
      @JoinColumn(name = "FLOOR_ID", nullable = false, referencedColumnName = "ID")
      private FloorEntity floor;
      ...
  }
  </code></pre>
  
  <p>requested entity :</p>
  
  <pre><code>@Entity(name = "Lamp")
  @Table(name = "LAMP")
  public class LampEntity {
  
      @ManyToOne
      @JoinColumn(name = "LOCATION_ID", referencedColumnName = "ID")
      private LocationEntity location;
  }
  </code></pre>
  
  <p>repository :</p>
  
  <pre><code>public interface LampRepository extends JpaRepository&lt;LampEntity, Long&gt; {
  
      @Query("SELECT lamp FROM Lamp lamp WHERE lamp.location.code = :locationCode AND TYPE(lamp.location) = Room")
      public List&lt;LampEntity&gt; findAllByRoomCode(@Param("code") String locationCode);
      ...
  }
  </code></pre>
  
  <p>I'm using <code>spring-data-JPA 1.4.1.RELEASE</code> with <code>Hibernate 4.2.7.Final</code> as provider.</p>
  
  <p>My questions are :</p>
  
  <ol>
  <li>Is it possible to do that with Spring data JPA ?</li>
  <li>In a old stackoverflow post i saw that Hibernate accepted it only with <code>InheritanceType.SINGLE_TABLE</code> but maybe now it's ok in 4.2.7 ?</li>
  <li>If not, what are my alternative if I want to keep my <code>InheritanceType.TABLE_PER_CLASS</code> strategy ?</li>
  </ol>
  
  <p>Thanks a lot</p>
  
  <hr>
  
  <p>Updated with unique constraints and relation between <code>Floor</code> and <code>Room</code></p>