У меня есть класс "Пользователь книги" и "Корзина".
1 пользователь может иметь одну или несколько книг в таблице корзины.
Я хочу отобразить это отношение, но получаю следующую ошибку:
javax.persistence.PersistenceException: [PersistenceUnit: default] Невозможно построить Hibernate SessionFactory;вложенное исключение - org.hibernate.persister.walking.spi.WalkingException: ассоциация уже посещена: AssociationKey (таблица = корзина, столбцы = {book_id})
класс корзины
@Entity
public class Basket {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name="book_id")
private Book book;
private long user_id;
public Basket() {}
public Basket(Book book, long user_id) {
this.book = book;
this.user_id = user_id;
}
// Getters and Setters
}
Книжный класс
@Entity
@Table(name = "book")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Book implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "title")
private String title;
@Column(name = "isbn")
private String isbn;
@Column(name = "quantity")
private Integer quantity;
@Column(name = "price")
private Double price;
@OneToMany(mappedBy = "book", fetch = FetchType.EAGER)
@Cache(usage = CacheConcurrencyStrategy.NONE)
@JsonIgnoreProperties("book")
private Set<SaleDetails> saleDetails = new HashSet<>();
@ManyToMany(fetch = FetchType.EAGER)
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@JoinTable(name = "book_author",
joinColumns = @JoinColumn(name = "books_id", referencedColumnName = "id"),
inverseJoinColumns = @JoinColumn(name = "authors_id", referencedColumnName = "id"))
@JsonIgnoreProperties("books")
private Set<Author> authors = new HashSet<>();
@ManyToMany(fetch = FetchType.EAGER)
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@JoinTable(name = "book_genre",
joinColumns = @JoinColumn(name = "books_id", referencedColumnName = "id"),
inverseJoinColumns = @JoinColumn(name = "genres_id", referencedColumnName = "id"))
private Set<Genre> genres = new HashSet<>();