我使用Spring Data JPA创建了一个表,所以这意味着我没有输入任何SQL代码。现在我得到了一个关于SQL语句中语法错误的警告,如下所示:
Syntax error in SQL statement "create table [*]user (id bigint not null, city varchar(255), fullname varchar(255), password varchar(255), phone_number varchar(255), state varchar(255), street varchar(255), username varchar(255), zip varchar(255), primary key (id))"; expected "identifier";
这是我的“用户”域的一部分,用于获取用户信息
@Entity
@Data
@NoArgsConstructor(access = AccessLevel.PRIVATE, force = true)
@RequiredArgsConstructor
public class User implements UserDetails{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private final String username;
private final String password;
private final String fullname;
private final String street;
private final String city;
private final String state;
private final String zip;
private final String phoneNumber;
其他方法无关紧要,因为它们只是覆盖UserDetails接口的布尔方法,只返回“true”
现在我得到了一个错误的异常Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException:
。当我运行并导航到web上的/register
页面时,我填写用户详细信息并提交,以便将其插入UserRepository:
import org.springframework.data.repository.CrudRepository;
import tacos1.User;
public interface UserRepository extends CrudRepository<User, Long> {
User findByUsername(String username);
}
我在网上看到这个错误:
There was an unexpected error (type=Internal Server Error, status=500).
could not prepare statement; SQL [insert into user (city, fullname, password, phone_number, state, street, username, zip, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?)];
原因:
Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "insert into [*]user (city, fullname, password, phone_number, state, street, username, zip, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?)"; expected "identifier";
1条答案
按热度按时间9lowa7mx1#
如果您的应用程序使用H2数据库,“User”是一个保留关键字,可以在文档中看到。
一个快速解决方法是将实体名称重命名为“Users”,或者将
NON_KEYWORDS=user
添加到JDBC URL。