JPA JoinColumn vs mappedBy says
The annotation @JoinColumn indicates that this entity is the owner of the relationship (that is: the corresponding table has a column with a foreign key to the referenced table),
Now I have below code where I have mentioned @JoinColumn
under college entity which is non owner entity and student is the owner entity as it has column pointing to primary key column in student table.
So it is reverse of above statement.
Does it mean above statement is applicable for one to one or many to one association not for one to many ?
@Entity
public class College {
.........
@OneToMany(cascade=CascadeType.ALL)
@JoinColumn(name="COLLEGE_COLLEGEID")
private List<Student> students;
}
@Entity
public class Student {
...
}
UPDATE :- i have college and student tables. Student has column college_collegeId which is foreign key to collegeId in college table. With below code i am able to save college and student entity where college_collegeId contains value pointing to foreign key to collegeId in college table
public void saveCollege() {
Student student1= new Student();
student1.setStudentName("Student1");
ArrayList<Student> list= new ArrayList<Student>();
list.add(student1);
College college1= new College();
college1.setCollegeName("College3");
college1.setCollegeId(1);
college1.setStudents(list);
getEntityManager().merge(college1);
}