Witam tworzę prosty system do tworzenia umów dla pracowników firm usługowych. Tworzę coś na zasadzie koszyka tzn ktoś tworzy załóżmy jakiś pakiet czegoś i można tam dodać okres trwania umowy. Te okresy trwania zapisuje do listy a potem po uzupełnieniu reszty formularza jest zapisywane do bazy danych razem z pakietem. Wszystko przy pierwszym dodaniu działa dobrze ale już przy kolejnym dostaje taki błąd.

could not execute statement; SQL [n/a]; constraint [UK_8pgjotcqm3iqy7vgu07jmhgvo]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement

a w konsoli mam błąd o duplikatach.

com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '1' for key 'UK_8pgjotcqm3iqy7vgu07jmhgvo'

podejrzewam że jest tu błąd w modelach ale nie wiem jak to naprawić.

@Entity
public class Periods {

    @GeneratedValue(strategy=GenerationType.AUTO)
    @Id
    private Long id;

    private String period;

    @ManyToOne
    private Product product;

    @ManyToOne
    private User userCreate;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getPeriod() {
        return period;
    }

    public void setPeriod(String period) {
        this.period = period;
    }

    public User getUserCreate() {
        return userCreate;
    }

    public void setUserCreate(User userCreate) {
        this.userCreate = userCreate;
    }

    public Product getProduct() {
        return product;
    }

    public void setProduct(Product product) {
        this.product = product;
    }
}
@Entity
public class Product {

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private Long id;

    private String name;

    @ManyToOne
    @JoinColumn(name = "category_id")
    private Category category;

    @OneToMany
    private List<Periods> periods = new ArrayList<>();

    private BigDecimal price;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Category getCategory() {
        return category;
    }

    public void setCategory(Category category) {
        this.category = category;
    }

    public BigDecimal getPrice() {
        return price;
    }

    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    public List<Periods> getPeriods() {
        return periods;
    }

    public void setPeriods(List<Periods> periods) {
        this.periods = periods;
    }

    public Product() {}
}

proszę o wyrozumiałość

podaje cały projekt oraz dla zobrazowania zdjęcie.

https://github.com/Baron762/System

https://zapodaj.net/847112bad0eef.png.html

Pozdrawiam.