Estou tentando salvar Product
no banco de dados, parece bem, mas sempre tenho esse erro de integridade.
SQL Error: 1062, SQLState: 23000 Duplicate entry '1' for key 'UK_miislg5rujgruv45l3hv00cn2'
MInhas Classes
@Entity
public class Product implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotNull
private String title;
@NotNull
private String description;
@NotNull
private double price;
@OneToOne(fetch = FetchType.EAGER, optional = false)
@JoinColumn(name = "category_id", nullable = false)
private Category category;
private boolean isSold;
@OneToOne(fetch = FetchType.EAGER, optional = false)
@JoinColumn(name = "currency_id", nullable = false)
private Currency currency;
@OneToOne(fetch = FetchType.EAGER, optional = false)
@JoinColumn(name = "user_id", nullable = false)
private User user;
@Nullable
@OneToMany(mappedBy = "product",
cascade = CascadeType.ALL, orphanRemoval = true)
private List<Images> images;
private Date createdDate = new Date();
@OneToOne(fetch = FetchType.EAGER,
cascade = CascadeType.ALL,
mappedBy = "product")
private View view;
@OneToOne(fetch = FetchType.EAGER)
@JoinColumn(name="type_id")
private Type type;
private Long viewCount;}
@Entity
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class Category implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
private String imagePath;
@OneToOne(cascade = CascadeType.ALL,
mappedBy = "category")
@JsonIgnore
private Product product;
@OneToMany(mappedBy = "category", fetch = FetchType.EAGER,
cascade = CascadeType.ALL)
private Set<Brand> brands;
}
@Entity
public class Currency implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String code;
private String currency;
private String region_country;
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
@OneToOne(mappedBy = "currency", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JsonIgnore
private Product product;
}
@Entity
public class Images implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String imagePath;
@JsonIgnore
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "product_id")
private Product product;
}
@Entity
public class Type implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotNull
private String name;
@OneToOne(fetch = FetchType.LAZY,
cascade = CascadeType.ALL,
mappedBy = "type")
@JsonIgnore
private Product product;
}
@Entity
public class User implements UserDetails, Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotEmpty
private String fullName;
@NotEmpty
@Email
@Column(unique = true)
private String email;
@NotNull
@Column(unique = true)
private int phoneNumber;
@NotEmpty
@Size(min = 5)
private String password;
private Date createAt = new Date();
@Nullable
private String picPath;
@Nullable
private String token;
@ManyToMany
@JoinTable(name = "user_roles", joinColumns = {@JoinColumn(
name = "user_id")},
inverseJoinColumns = {@JoinColumn(name = "role_id")})
private List<Role> roles;
@OneToOne(fetch = FetchType.EAGER,
cascade = CascadeType.ALL,
mappedBy = "user")
@JsonIgnore
private Product product;
@OneToOne(fetch = FetchType.LAZY,
cascade = CascadeType.ALL,
mappedBy = "user")
private View view;
}
@Entity
public class View implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@OneToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "user_id", nullable = false)
@JsonIgnore
private User user;
@OneToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "product_id", nullable = false)
@JsonIgnore
private Product product;
}