hello, In my apllication, there are students and classes. a student can take many classes. So there is OneToMany <--> ManyToOne relationship. Im my case, the best implementation is using a join table. I followed examples I found on internet and at books. So I wrote the code (summary) below..
class Class:
@Id @GeneratedValue @Column(name="CLASS_ID") private Integer id; private String name; @ManyToOne @JoinTable(schema="temel", name = "STUDENT_CLASS", inverseJoinColumns = @JoinColumn(name = "STUDENT_ID", referencedColumnName = "STUDENT_ID"), joinColumns = @JoinColumn(name = "CLASS_ID", referencedColumnName = "CLASS_ID")) private Student student;
(Constructor, getters, setters)
class Student:
@Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "STUDENT_ID") private Integer id;
private String name;
@OneToMany(mappedBy = "student", cascade=CascadeType.ALL) private Collection<Class> classes = new ArrayList<Class>();
(Constructor, getters, setters)
because I use "hibernate.hbm2ddl.auto" all tables, including join table, are created. When I push save button, the student and the class data is saved correctly. but there is no information in my join table. I tried many things. I can not find my mistake. I'd appreciate for any help and tips... thanks...
|