title: Problem with Spring Data JPA @Query Annotation (error in SQL syntax)
body: <p><strong>EDIT:</strong> I want to check if a certain user has a privilege in a group. If there is a better solution without querying all his privileges please tell me.</p>
  
  <p>The following query gives me one error I couldn't understand:</p>
  
  <pre><code>@Repository
  public interface PrivilegeRepository extends JpaRepository&lt;Privilege, Long&gt; {
  
      @Query("select p from Privilege p " +
              "inner join p.userTypes " +
              "inner join UserGroup u " +
              "where u.user.id=:uid and u.group.id=:gid")
      List&lt;Privilege&gt; getPrivilegesOfUser(@Param("uid") Long uid, @Param("gid") Long gid);
  
  }
  </code></pre>
  
  <p>error: </p>
  
  <pre><code>com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where usergroup1_.user_id=28 and usergroup1_.group_id=18' at line 1
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_144]
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_144]
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_144]
      at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_144]
  </code></pre>
  
  <p>UserGroup entity</p>
  
  <pre><code>@Entity
  @Table(name = "user_to_group")
  public class UserGroup {
  
      @EmbeddedId
      private UserGroupId id;
  
      @ManyToOne(fetch = FetchType.LAZY,
              cascade = {CascadeType.DETACH, CascadeType.MERGE,
                      CascadeType.REFRESH, CascadeType.PERSIST})
      @MapsId("userId")
      @JoinColumn(name = "user_id", insertable = false, updatable = false)
      private User user;
  
      @ManyToOne(fetch = FetchType.LAZY,
              cascade = {CascadeType.DETACH, CascadeType.MERGE,
                      CascadeType.REFRESH, CascadeType.PERSIST})
      @MapsId("groupId")
      @JoinColumn(name = "group_id", insertable = false, updatable = false)
      private Group group;
  
      @ManyToOne(fetch = FetchType.LAZY,
              cascade = {CascadeType.DETACH, CascadeType.MERGE,
                      CascadeType.REFRESH, CascadeType.PERSIST})
      @JoinColumn(name = "user_type_id")
      private UserType userType;
  
      @Column(name = "is_blocked",
      insertable = false)
      private boolean isBlocked = false;
  </code></pre>
  
  <p>I tried first the equivalent query in the MYSQL Workbench and worked just fine. Nothing with Jpa repository implementation.
  This is the code that works on MYSQL:</p>
  
  <pre><code>select p.name from privilege p 
      inner join user_type_to_privilege utp 
          on p.id=utp.privilege_id
      natural join user_to_group utg
      where utg.user_id=16 and
          utg.group_id=9;
  </code></pre>
  
  <p>This is the dialect I use: <code>spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQLDialect</code>
  Is this outdated or something?</p>