I have two entities with many to many relation
Card
@Entity
@Data
@Table(name = "card")
public class Card {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false, name = "name")
private String name;
@Column(nullable = false, name = "type")
private String type;
}
and Deck
@Entity
@Data
@Table(name = "deck")
public class Deck {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne
private User owner;
@Column(nullable = false, name = "name")
private String name;
@Column(nullable = false, name = "access_level")
private String accessLevel;
@OneToMany(mappedBy = "deck", cascade = CascadeType.ALL)
List<CardDeckIntersection> cardDeckIntersections;
}
thus i crated join table with composite primary key:
@Data
@Entity
@Table(name = "card_deck_intersection")
@IdClass(CardDeckIntersectionId.class)
public class CardDeckIntersection {
@Id
@ManyToOne
private Card card;
@Id
@ManyToOne
private Deck deck;
}
and composite key class
@Data
public class CardDeckIntersectionId implements Serializable {
private Card card;
private Deck deck;
}
Every time i am trying to save an CardDeckIntersection
element i get this exception:
org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.lang.Long' to required type 'Card' for property 'card'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.Long' to required type 'Card' for property 'card': no matching editors or conversion strategy found