Spring Boot和Spring Data org.hibernate.exception.SQLGrammarException:无法提取ResultSet

时间:2018-08-23 09:37:41

标签: spring-boot spring-data

我已经使用Spring Data设置了一个新的Spring Boot应用程序。我正在尝试对数据库执行非常简单的查询,但是错误日志报告查询存在问题,我不知道为什么。

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

数据库表的设置如下;

BIGINT | ID VARCHAR |名称 文字| storage_path TINYINT(1)|活跃

Line实体看起来像这样;

@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;
    }

在使用Spring Data时,我的存储库如下所示:

@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);

}

我正在尝试在LineRepository上调用findAll()方法,但这会引发上述错误。

编辑:下面是正在执行的查询,我看不出有什么问题;

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 个答案:

答案 0 :(得分:0)

事实证明,“行”是MySQL中的保留字,因此为什么查询无效。

我已经更改了表格的名称,它已经解决了该问题。