inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

자바 ORM 표준 JPA 프로그래밍 - 기본편

안녕하세요 1:1 연관관계저장 질문 드립니다 ㅠㅠ

210

한희성

작성한 질문수 10

0

안녕하세요. 1:1 연관관계 저장 관련해서 현재 잘 안되고 있어 질문 드립니다...ㅠ
 
users 테이블과, user_detail 테이블은 1:1 관계이고 save(usersEntity) 객체로 한번에 저장하려니 계속 user_seq null 오류가 발생합니다.
users 테이블의 pk 는 user_detail 테이블에 fk 로 가지고 있으며 소스는 아래와 같습니다 ㅠ
 
@Getter
@Entity
@Table(name = "users")
public class UsersEntity extends TimeAndUserIdEntity {

@Id
@Column(name = "seq")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long seq;

private String userId;

private String password;

private String nickName;

@Enumerated(EnumType.STRING)
private GenderType gender;

private LocalDate birthday;

private String profileImagePath;

@Enumerated(EnumType.STRING)
private SignUpType signUpType;

@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "user_seq")
private UserDetailEntity userDetailEntity;

//    @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
// @JoinColumn(name = "user_seq", foreignKey = @ForeignKey(name = "user_seq"))
// private UserDetailEntity userDetailEntity;

public UsersEntity() {
}

@Builder(builderClassName = "byInsertForUsersEntity", builderMethodName = "byInsertForUsersEntity")
public UsersEntity(String userId, String password, Map<String, String> agreeMap) {
super("system");
this.userId = userId;
this.password = password;
this.signUpType = SignUpType.DEFAULT;
this.userDetailEntity = new UserDetailEntity(agreeMap);
}
}


@Getter
@Entity
@Table(name = "user_detail")
public class UserDetailEntity extends TimeAndUserIdEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long seq;

private Long userSeq;

private String lunchAlarmUseYn;

private LocalTime lunchAlarmTime;

private String dinnerAlarmUseYn;

private LocalTime dinnerAlarmTime;

private String eventAlarmUseYn;

private String serviceAlarmUseYn;

@Enumerated(EnumType.STRING)
private UserStatusType userStatusType;

private String termsAgree;

private String privacyAgree;

private String locationAgree;

public UserDetailEntity() {
}

public UserDetailEntity(Map<String, String> agreeMap) {
super("system");
this.lunchAlarmUseYn = "y";
this.lunchAlarmTime = LocalTime.of(11, 30);
this.dinnerAlarmUseYn = "y";
this.dinnerAlarmTime = LocalTime.of(11, 30);
this.eventAlarmUseYn = "y";
this.serviceAlarmUseYn = "y";
this.userStatusType = UserStatusType.SIGNING;
this.termsAgree = agreeMap.get("terms");
this.privacyAgree = agreeMap.get("privacy");
this.locationAgree = agreeMap.get("location");
}

저장 로직은 아래와 같습니다

java JPA

답변 2

0

한희성

저장 로직은 다음과 같습니다

0

David

조금 더 자세히 분석하기 위해 아래 가이드를 따라 프로젝트 전체를 올려주시길 부탁드립니다.


전체 프로젝트를 압축해서 구글 드라이브로 공유해서 링크를 남겨주세요.
구글 드라이브 업로드 방법은 다음을 참고해주세요.

https://bit.ly/3fX6ygx

주의: 업로드시 권한 문제 꼭 확인해주세요

추가로 다음 내용도 코멘트 부탁드립니다.

1. 실행 방법을 알려주세요.
2. 어떻게 문제를 확인할 수 있는지 자세한 설명을 남겨주세요.

감사합니다

0

David

안녕하세요. 한희성님, 공식 서포터즈 David입니다.

저장을 수행하는 코드와 저장시 발생하는 에러 전체를 함께 올려주시길 부탁드립니다.

감사합니다.

벌크연산에서 member.getAge 호출 시 영속성 컨텍스트에서 데이터를 가져오는건가요?

0

55

2

inheritance startegy 선택시 고려사항

0

36

1

Entity 동등성 비교

0

38

1

실무 조언 관련 질문입니다.

0

64

1

H2데이터베이스 파일 생성

0

76

2

서브쿼리 강의에서 ALL 예시 관련 질문드립니다.

0

66

2

수정또는 삭제시 영속성 엔티티에 값이 무조건 있어야 하나요?

0

62

1

JPQL 메소드와 락

0

62

1

Delivery @OneToOne

0

70

1

17강 4~5분대 테이블 값 조회가 안됩니다.

0

104

2

UnsupportedOperationException 발생

0

97

3

H2 Database 연결이 안됩니다.

0

101

2

연관관계 매핑 질문드립니다.

0

93

2

h2데이터베이스 실행오류

0

114

2

persistence.xml

0

119

2

양방향 연관관계에서 연관관계의 주인(mappedBy)을 왜 꼭 정해야 하나요?

0

87

1

영속성 컨텍스트

0

74

1

JPA 프록시

0

105

1

Native Query와 MyBatis

0

81

1

영속성 컨텍스트는 어떤 메모리에 저장되는건가요?

0

97

1

임베디드 타입 예시 코드 관련 질문

0

125

3

명시적 조인에서 별칭을 주면 왜 객체에 접근할 수 있나요

0

100

3

인텔리제이 패키지 커서 단축키 질문

0

112

2

혹시 현재는 ID 데이터 타입이 String이면 안되나요?

0

151

1