-1

I need to create a OneToMany mapping. I am a beginner in Hibernate. I need an example where a student is enrolled in multiple subjects (courses). I am referring this website to get started. I liked the simplicity of code for the beginners.

Tutorial Link One

Tutorial link Two

halfer
  • 19,824
  • 17
  • 99
  • 186
sanjith kumar
  • 325
  • 2
  • 3
  • 13
  • It's worth knowing that on Stack Overflow requests for tutorials are off-topic, as historically we have found that such questions are used to seed spam links. It is better therefore to show us what you have tried using the manual and then someone perhaps can show you where your code is going wrong - the advantage with this approach is that posters learn to fend for themselves, and sometimes end up achieving their goal without any help at all. – halfer Jan 18 '16 at 08:26

1 Answers1

0

Your code should look like below

@Entity
class Student{

    @OneToMany
    @JoinColumn(name = "student_fk")
    List<Subject> subject;
}

This will create a foreign key (column for student id) in subject table.

Pallav Jha
  • 3,409
  • 3
  • 29
  • 52