사용자에게 몇 가지 프로필이있는 유스 케이스가 있습니다. 그래서 일대 다 연관입니다.대상 엔티티가 복합 기본 키를 가지고 있지만 소스가 아닌 경우 많은 문제 매핑 1
이것은 pseudo sql에서 이러한 레거시 테이블을 통해 매핑됩니다.
TABLE USER
(
ID PK
SURNAME VARCHAR2(45 BYTE) NOT NULL,
NAME VARCHAR2(45 BYTE) NOT NULL,
USER_ID NUMBER
)
TABLE USER_PROFILES
(
USER_ID NUMBER NOT NULL,
ID_PROFILO NUMBER NOT NULL,
DESCRIPTION VARCHAR2(32 BYTE)
)
이 자바 매핑 :
Exception Description: The @JoinColumns on the annotated element [field profiles] from the entity class [User] is incomplete. When the source entity class uses a composite primary key, a @JoinColumn must be specified for each join column using the @JoinColumns. Both the name and the referencedColumnName elements must be specified in each such @JoinColumn.
: 나는 UserDao에서 사용자를 얻을 때 나는이 예외가 발생
@Entity
@Table(name = "USER)
public class User{
@Id
@Column(name = "ID")
private String id;
@OneToMany(fetch= FetchType.EAGER)
@JoinColumns({ @JoinColumn(name = "USER_ID", referencedColumnName = "USER_ID")})
private List<UtenteProfilo> profiles;
}
과 userprofiles 클래스
@Entity
@Table(name = "USER_PROFILES")
@IdClass(UserProfile.UserProfileId.class)
public class UserProfile implements java.io.Serializable {
@Id
@Column(name = "USER_ID", nullable = false)
private Long userId;
@Id
@Column(name = "ID_PROFILO", nullable = false, insertable = false, updatable = false)
private Long profiloId;
private String description;
static public class UserProfileId implements Serializable {
@Id
@Column(name = "USER_ID", nullable = false)
Long userId;
@Id
@Column(name = "ID_PROFILO", nullable = false)
Long profiloId;
}
}
문제는 그 일에 e 소스 엔티티 (1-N 연관을 갖는 오브젝트) 나는 하나의 컬럼 만 가지고 있습니다.
대상 엔터티의 ID를 변경하려고했습니다. 그래서 user_id를 키로 선언하는 user_profiles 클래스에서 : 그러나 이렇게하면 jpa가 질의를 생성 할 때 오직 하나의 user_profiles occurence 만 처리하여 관계를 1-1로 만듭니다.
문제를 수정하고 연결을 만드는 방법을 알려주세요.
종류는 마시모