H2 SQLGrammarException:无法准备语句
我有一个带有 h2 数据库的 Spring Boot 应用程序,该数据库由 UserRepository 寻址。我正在尝试使用 Spring security 使用 jdbc(这里是 Hibernate)
@Entity
@Table(name="USER")
public class User {
@Id
@Column(name="USER_ID")
private long id;
@Column(name="USERNAME, nullable = false, unique = true")
private String username;
@Column(name="PASSWORD")
private String password;
/*setter/getter follows */
}
存储库进行身份验证:-
public interface UserRepository extends JpaRepository<User, Long>{
User findByUsername(String username);
}
SQL:
CREATE TABLE USER(
USER_ID BIGINT AUTO_INCREMENT PRIMARY KEY,
USERNAME VARCHAR(128) NOT NULL UNIQUE,
PASSWORD VARCHAR(256) NOT NULL
);
INSERT INTO USER (USERNAME,PASSWORD) VALUES('jdoe','foobar');
But when enter correct username and password, it is not accepting it.
Exception:
SQL Error: 42001, SQLState: 42001
2022-03-04 13:43:18.571 ERROR 17924 --- [nio-8080-exec-7] o.h.engine.jdbc.spi.SqlExceptionHelper : Syntax error in SQL statement "SELECT USER0_.USER_ID AS USER_ID1_0_, USER0_.PASSWORD AS PASSWORD2_0_, USER0_.USERNAME, NULLABLE = FALSE, UNIQUE[*] = TRUE AS USERNAME3_0_ FROM USER USER0_ WHERE USER0_.USERNAME, NULLABLE = FALSE, UNIQUE = TRUE=? "; expected "*, NOT, EXISTS, INTERSECTS, SELECT, FROM, WITH"; SQL statement:
select user0_.user_id as user_id1_0_, user0_.password as password2_0_, user0_.username, nullable = false, unique = true as username3_0_ from user user0_ where user0_.username, nullable = false, unique = true=? [42001-196]
I have a spring boot application with an h2 database that is addressed by a UserRepository. I am trying to use Spring security to authenticate using jdbc(Hibernate here)
@Entity
@Table(name="USER")
public class User {
@Id
@Column(name="USER_ID")
private long id;
@Column(name="USERNAME, nullable = false, unique = true")
private String username;
@Column(name="PASSWORD")
private String password;
/*setter/getter follows */
}
Repository:-
public interface UserRepository extends JpaRepository<User, Long>{
User findByUsername(String username);
}
SQL:
CREATE TABLE USER(
USER_ID BIGINT AUTO_INCREMENT PRIMARY KEY,
USERNAME VARCHAR(128) NOT NULL UNIQUE,
PASSWORD VARCHAR(256) NOT NULL
);
INSERT INTO USER (USERNAME,PASSWORD) VALUES('jdoe','foobar');
But when enter correct username and password, it is not accepting it.
Exception:
SQL Error: 42001, SQLState: 42001
2022-03-04 13:43:18.571 ERROR 17924 --- [nio-8080-exec-7] o.h.engine.jdbc.spi.SqlExceptionHelper : Syntax error in SQL statement "SELECT USER0_.USER_ID AS USER_ID1_0_, USER0_.PASSWORD AS PASSWORD2_0_, USER0_.USERNAME, NULLABLE = FALSE, UNIQUE[*] = TRUE AS USERNAME3_0_ FROM USER USER0_ WHERE USER0_.USERNAME, NULLABLE = FALSE, UNIQUE = TRUE=? "; expected "*, NOT, EXISTS, INTERSECTS, SELECT, FROM, WITH"; SQL statement:
select user0_.user_id as user_id1_0_, user0_.password as password2_0_, user0_.username, nullable = false, unique = true as username3_0_ from user user0_ where user0_.username, nullable = false, unique = true=? [42001-196]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不错的错误:
->
Nice mistake:
->