웹 백엔드 개발/Spring Boot
[SpringBoot/오류 해결] Maria DB에 table이 추가되지 않는 문제
iinana
2025. 4. 3. 08:11
Maria DB를 활용하여 User 관련 기능들을 개발하던 중, user table이 DB에 추가되지 않는 문제가 발생했다. 이상한 점은 refresh token table은 잘 추가가 되었는데, User table만 추가되지 않았다는 점이다.
아래 코드는 각각 refresh token과 user에 관한 코드이다.
/** RefreshToken.java **/
@NoArgsConstructor
@Getter
@Entity
public class RefreshToken {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="id", updatable=false)
private Long id;
@Column(name="user_id", nullable=false, unique=true)
private Long userId;
@Column(name="refresh_token", nullable=false)
private String refreshToken;
/** 생략 */
}
/** User.java **/
@Entity
@Table(name="users")
@Getter
public class User implements UserDetails {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="user_id", updatable=false)
private UUID userId;
@Column(name="email", nullable=false, unique=true)
private String email;
@Column(name="user_ident", nullable=false, unique=true)
private String userIdent;
@Column(name="password", nullable=false)
private String password;
/** 생략 */
}
여러 차이점을 후보로 두고 생각했지만, 결국 문제는 id field의 type이었다. MariaDB에서 UUID 타입을 @GeneratedValue(strategy = GenerationType.IDENTITY)와 함께 사용하는 경우 문제가 될 수 있다고 한다. 따라서 User entity에서도 id의 type을 모두 Long으로 수정해 주었다.
/** User.java **/
@Entity
@Table(name="users")
@Getter
public class User implements UserDetails {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="user_id", updatable=false)
private Long userId;
@Column(name="email", nullable=false, unique=true)
private String email;
@Column(name="user_ident", nullable=false, unique=true)
private String userIdent;
@Column(name="password", nullable=false)
private String password;
/** 생략 */
}
728x90
반응형