Based on this tutorial I'm trying to create Many-to-Many Relationship Using a Composite Key
Eventually I get the following error
The composite key itself have the following structure:
@Embeddable
@Data
public class MovieRatingsKey implements Serializable {
@Column(name = "movieid")
private Movies movieid;
@Column(name = "userid")
private Usrs userid;
}
Class Movies:
@Entity
@Data
public class Movies {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer movieid;
/*not related to the question*/
@OneToMany(mappedBy = "movieid", fetch = FetchType.LAZY)
private Set<Ratings> rates = new HashSet<>();
}
User:
@Entity
@Data
public class Usrs {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer userid;
@OneToMany(mappedBy = "userid", fetch = FetchType.LAZY)
private Set<Ratings> rates = new HashSet<>();
}
Associative table:
@Entity
@Data
public class Ratings {
@EmbeddedId
private MovieRatingsKey id;
/*not related to the question*/
@ManyToOne
@MapsId("movieid")
@JoinColumn(name = "movieid")
Movies movie;
@ManyToOne
@MapsId("userid")
@JoinColumn(name = "userid")
Usrs user;
}
question from:
https://stackoverflow.com/questions/66051765/nested-exception-is-org-hibernate-annotationexception-mappedby-reference-an-unk 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…