이미지가있는 다양한 항목에 이미지를 매핑하는 이미지 매핑 테이블이 있습니다. 이 작업은 데이터베이스에서 수동으로 항목을 만들고 검색 할 때 예상대로 작동하지만 테스트를 시도 할 때 아래 오류와 함께 실패합니다. 테스트를 위해 h2와 함께 최대 절전 모드를 사용하고 dev에 대해 MySQL을 사용하여 최대 절전 모드로 전환합니다.테스트에서 테이블을 만들 수 없음 (최대 절전 모드 및 H2)
다음은 테이블 생성의 오류입니다.
ERROR - Unsuccessful: create table ImageMapping (image_mapping_id integer not null, category_id integer, image_id integer, product_id integer, product_item_id integer, product_option_id integer generated by default as identity, primary key (product_option_id, image_id), unique (image_id))
ERROR - Attempt to define a second primary key; SQL statement:
create table ImageMapping (image_mapping_id integer not null, category_id integer, image_id integer, product_id integer, product_item_id integer, product_option_id integer generated by default as identity, primary key (product_option_id, image_id), unique (image_id)) [90017-168]
이미지 매핑 엔티티. 오류가 언급되는 다른 필드입니다
@JsonAutoDetect
@JsonIgnoreProperties(ignoreUnknown = true)
@Entity
@Table(name="ImageMapping")
public class ImageMapping {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "image_mapping_id")
private int imageMappingId;
@Column(name="product_option_id")
private int productOptionId;
@Column(name="product_item_id")
private int productItemId;
@Column(name="product_id")
private int productId;
@Column(name="image_id")
private int imageId;
@Column(name="category_id")
private int categoryId;
내가 엔티티 것을 포함하고있는 product_option_id입니다. 잘못 관절 식 주석을 사용하는 것처럼
@JsonAutoDetect
@JsonIgnoreProperties(ignoreUnknown = true)
@Entity
@Table(name="ProductOptions")
public class ProductOptions implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "product_option_id")
private int productOptionId;
@JoinTable(
name="ImageMapping",
joinColumns = @JoinColumn(name = "product_option_id"),
inverseJoinColumns = @JoinColumn(name = "image_id")
)
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private Set<Image> productOptionImageGroup;
@JoinColumn(name = "image_id")
@OneToOne
private Image optionImage;
@Column(name = "product_option_description")
private String productOptionDescription;
제프, 정말 멋진 답변이었습니다. 나는 1 주일 이상 이걸로 고투하고 있었고 아무것도 찾지 못했습니다. 그래서 당신이 보내준 게시물이 다른 제목으로 거의 같은 이슈 였기 때문에 검색 방법에 대해 연구해야한다고 생각합니다. 다시 한 번 감사드립니다! – zmanc
문제 없으니 기꺼이 도와주세요. 해피 코딩! – jeff