연습용더미1
440
2021-01-22 17:58:20
1
165

JPA @GeneratedValue 컬럼 값 할당 질문입니다.



@Entity
@SequenceGenerator(name="MEMBER_SEQ_GENERATOR",
sequenceName="MEMBER_SEQ",
initialValue=21,
allocationSize=1
)
data class Member(
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "MEMBER_SEQ_GENERATOR")
@Column(insertable = true)
val id: Long?,
@Column(unique = true, nullable = false, length = 15)
var memberId: String,
@Column(nullable = false, length = 20)
var password: String,
@Column(unique = true, nullable = false)
var email: String,
@Column(unique = true, nullable = false)
var phone: String,
var address: String?,
@Column(insertable = false, updatable = false, columnDefinition="TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
val regDate: Date?,
@Column(nullable = false, columnDefinition = "number(1,0) default 0")
val certified: Boolean?
)

이렇게 생성한 id 컬럼에 save() 메서드로 id값을 직접 할당하려고 해도 값을 자동으로 바꿔버립니다.

직접할당하는 방법은 없나요?

Entity로 넣어도 아래처럼 id값만 따로 인식한 후에 초기화합니다.

2021-01-22 17:34:13.666 TRACE 6920 --- [  restartedMain] o.h.type.descriptor.sql.BasicBinder      : binding parameter [1] as [BIGINT] - [1]
Hibernate: 
    select
        member_seq.nextval 
    from
        dual
Hibernate: 
    insert 
    into
        member
        (address, certified, email, member_id, password, phone, id) 
    values
        (?, ?, ?, ?, ?, ?, ?)
2021-01-22 17:34:13.677 TRACE 6920 --- [  restartedMain] o.h.type.descriptor.sql.BasicBinder      : binding parameter [1] as [VARCHAR] - [null]
2021-01-22 17:34:13.678 TRACE 6920 --- [  restartedMain] o.h.type.descriptor.sql.BasicBinder      : binding parameter [2] as [BIT] - [true]
2021-01-22 17:34:13.678 TRACE 6920 --- [  restartedMain] o.h.type.descriptor.sql.BasicBinder      : binding parameter [3] as [VARCHAR] - [dummy@asd.com]
2021-01-22 17:34:13.678 TRACE 6920 --- [  restartedMain] o.h.type.descriptor.sql.BasicBinder      : binding parameter [4] as [VARCHAR] - [dummy]
2021-01-22 17:34:13.678 TRACE 6920 --- [  restartedMain] o.h.type.descriptor.sql.BasicBinder      : binding parameter [5] as [VARCHAR] - [123]
2021-01-22 17:34:13.678 TRACE 6920 --- [  restartedMain] o.h.type.descriptor.sql.BasicBinder      : binding parameter [6] as [VARCHAR] - [010-1111-1111]
2021-01-22 17:34:13.679 TRACE 6920 --- [  restartedMain] o.h.type.descriptor.sql.BasicBinder      : binding parameter [7] as [BIGINT] - [22]

0
  • 답변 1

  • 훈마로
    666
    2021-01-22 19:03:43

    generatedvalue를 안 쓰시면 됩니다;

  • 로그인을 하시면 답변을 등록할 수 있습니다.