Spring Boot and Spring Data org.hibernate.exception.SQLGram



我已经使用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 瓦查尔 |名字 正文 |storage_path 天印(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 数据时,我的存储库如下所示;

@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_

事实证明,"行"在MySQL中是一个保留字,因此为什么查询无效。

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

最新更新