0

I've setup a new Spring Boot application using Spring Data. I'm trying to perform a really simple query on the database, but the error logs are reporting that there's something wrong with the query, and I can't figure out why.

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 'lines line0_' at line 1

The Database Table is setup as follows;

lines

BIGINT | id VARCHAR | name TEXT | storage_path TINYINT(1) | active

The Line entity looks like this;

@Entity
@Table(name="lines")
public class Line {

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

    @Column(name="name")
    private String name;

    @Column(name="storage_path")
    private String storagePath;

    @Column(name="active", columnDefinition = "TINYINT(1)")
    private Boolean active;
    }

As I'm using Spring Data, my repository looks like this;

@Repository
public interface LineRepository extends CrudRepository<Line, Long> {

    /**
     * Return a list of lines by their active value
     * @param active the active value
     * @return List of lines
     */
    public List<Line> getByActive(Boolean active);

}

All I'm trying to do it call the findAll() method on the LineRepository, but it's raising the error above.

EDIT: Below is the query being executed, I can't see anything wrong with it;

SELECT
        l 
    FROM
        Line l */ select
            line0_.id as id1_0_,
            line0_.active as active2_0_,
            line0_.name as name3_0_,
            line0_.storage_path as storage_4_0_ 
        from
            lines line0_
1
  • Do you have any other exception or error except this one liner? Commented Aug 23, 2018 at 10:25

1 Answer 1

1

It turns out that 'lines' is a reserved word in MySQL, hence why the queries where invalid.

I've changed the name of my table and it has resolved the issue.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.