Click here to Skip to main content
15,878,003 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have to Entity and relationship type between them ManyToMany.


@SuppressWarnings("JpaDataSourceORMInspection")
@Data
@Entity
public class Student {

    @Id
    private Long id;

    private Integer anotherId;

    @ToString.Exclude
    @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinTable(name = "student_course", joinColumns = @JoinColumn(name = "another_id", referencedColumnName = "anotherId"),
            inverseJoinColumns = @JoinColumn(name = "course_id"))
    private Set<Course> courses = new HashSet<>();

}



@Data
@Entity
public class Course {

    @Id
    private Long id;

    @ToString.Exclude
    @ManyToMany(mappedBy = "courses", fetch = FetchType.LAZY)
    @JsonIgnoreProperties("courses")
    private Set<Student> students=new HashSet<>();

}


Here is what I want:

I want my another_id column, which will be created when the junction table is created, to match the anotherId variable in my Student entity, but instead it only matches the id variable.

Can you tell me something about how to solve the problem I am experiencing?


What I have tried:

İ have tried to many way, but I couldn't.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900