'QuerySyntaxException - unexpected token: a (SQL statement not correct?)

I get following error message when trying to fire an SQl Statement....the exception:

QuerySyntaxException: unexpected token: a near line 1, column 127 [SELECT DISTINCT e FROM com.taqwaapps.entity.Event e, com.taqwaapps.entity.Appointment a WHERE e.eventId = a.event.eventId AND a.district.city.name = 'Jeddah' ]

It seems that following SQL Statement is not correct:

@Query("SELECT DISTINCT e "
        + "FROM Event e, Appointment a "
        + "WHERE e.eventId = a.event.eventId "
        + "AND a.district.city.name = 'Jeddah' ")
List<Event> getEventsFiltered(); 

My Objects are:

@Entity
public class Event {

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long eventId;
}

and

@Entity
public class Appointment {
    
    @JsonIgnore
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "eventId")
    private Event event; 

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "districtId")
    private District district; 

What is wrong?



Solution 1:[1]

I found the Problem:

In the past in school time I learned from my informatics Teacher that in SQL it can happen that there is an hidden character which we entered or which got entered but we dont see it. So just write the SQL again using plain writing

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 skm