Home > Mobile >  Spring JPA "syntax error at end of input"
Spring JPA "syntax error at end of input"

Time:12-19

I get this error: syntax error at end of input when I try to run this query

@Query(value="SELECT p.description,p.review,p.title,p.minutes, p.id, w.lat1,w.lat2,w.lon1,w.lon2 FROM post p " 
            "inner join p.waypoints w", nativeQuery = true)

This is my first entity:

@Table(name = "\"post\"")

public class Post {

private String title;
private String description;
private int review;
private String minutes;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(columnDefinition = "serial",name="id")
private Long id;

@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL,mappedBy = "post")
private Waypoints way;

}

This is my second entity

@Table(name = "\"waypoints\"")

public class Waypoints {

private double lat1;
private double lat2;
private double lon1;
private double lon2;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(columnDefinition = "serial", name="way_id")
private Long way_id;



 @OneToOne(fetch = FetchType.LAZY,optional = false)
    @JoinColumn(name = "id", nullable = false)
    private Post post;

}

And when I try to run it it gives my this error:

* Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet] with root cause

org.postgresql.util.PSQLException: ERROR: syntax error at end of input*

Any solutions?

CodePudding user response:

It looks like you're missing the on clause of your join. E.g., assuming the "waypoints" table has a "pid" column the corrolates to the posts' "id" column:

@Query(value="SELECT p.description,p.review,p.title,p.minutes, p.id, w.lat1,w.lat2,w.lon1,w.lon2 FROM post p " 
             "inner join waypoints w on p.id = w.pid", nativeQuery = true)
  • Related