im new on spring data jpa and i had a problem. I dont know how to add an atribute between a entity and a relation.
1 Student have 1 course, 1 Course have 0:N Student
1 CustomChallenge have 1 Course, 1 Course have 0:N CustomChallege.
My doubt is how can i represent when a student from one course done a CustomChallenge? And how can i add an atributte? There is something else i should change or improve? Thanks for reading to everyon Model Diagram Class User
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class User {
@Id
@GeneratedValue (
generator="system-uuid",
strategy=GenerationType.SEQUENCE
)
@GenericGenerator(name="system-uuid", strategy = "uuid2")
private String id;
@NotBlank
@Column(unique = true, length=10)
private String ci;
Class Student
@Entity
@PrimaryKeyJoinColumn
public class Student extends User implements Cloneable{
@ManyToOne
@JsonManagedReference
@NotNull
private Course enrolledCourse;
Class Teacher
@Entity
@PrimaryKeyJoinColumn
public class Teacher extends User {
@OneToMany(mappedBy = "teacher")
@JsonProperty("coursesGiven")
@JsonBackReference
private List<Course> coursesGiven=new ArrayList<Course>();
Class CustomChallenge
@Entity
public class CustomChallenge{
@Id
@GeneratedValue (
generator="system-uuid",
strategy=GenerationType.SEQUENCE
)
@GenericGenerator(name="system-uuid", strategy = "uuid2")
private String id;
@NotBlank
@Column(length = 50)
private String name;
@Entity
@Table
public class Course {
@Id @GeneratedValue
private int id;
@NotBlank
@Column(length=64)
@JsonProperty
private String name;
@ManyToOne
@JsonManagedReference
@JoinColumn
private Teacher teacher;
@OneToMany(mappedBy = "enrolledCourse")
@JsonBackReference
private List<Student> studentList=new ArrayList<Student>();