Spring Securityのユーザ認証でちょこっと躓いた

DB認証を設定しようとして

@Entity
public class User implements UserDetails {

private static final long serialVersionUID = 1L;

public enum Authority {ROLE_USER, ROLE_ADMIN}

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

@Column(nullable = false, unique = true)
private String username;

@Column(nullable = false)
private String password;

Userというクラス名でテーブルの生成をしようとしたら、以下のエラーが発生

Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near “user”Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near “user”  ポジション: 13 at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2455) ~[postgresql-9.4.1212.jre7.jar:9.4.1212.jre7] at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2155) ~[postgresql-9.4.1212.jre7.jar:9.4.1212.jre7] at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:288) ~[postgresql-9.4.1212.jre7.jar:9.4.1212.jre7] at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:430) ~[postgresql-9.4.1212.jre7.jar:9.4.1212.jre7] at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:356) ~[postgresql-9.4.1212.jre7.jar:9.4.1212.jre7]

Postgresの予約語とかさなったとのこと。リンク先のとりあえずの手段として以下のようにエスケープを二重にしたら動いた。(password列も必要とのこと)

@Entity
@Table(name = “`USER`”)
public class User implements UserDetails {

ただ、そもそも予約語と重ならないほうがよいよということなので後で変える

 

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です