H2 SQLGrammarException:无法准备语句

发布于 2025-01-11 11:13:26 字数 1645 浏览 0 评论 0原文

我有一个带有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云裳 2025-01-18 11:13:26

不错的错误:

@Column(name="USERNAME, nullable = false, unique = true")

->

@Column(name="USERNAME", nullable = false, unique = true)

Nice mistake:

@Column(name="USERNAME, nullable = false, unique = true")

->

@Column(name="USERNAME", nullable = false, unique = true)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文