0

I have 2 tables.

Student (id,name,class_id)<br>
class(id,name)

student relates to class table through class_id

after using hibernate and generate into object, I'll have 2 objects

Student { int id; String name; Class class }
Class {int id; String name; Set<Student> student}

I want to save student information using hibernate (session.save(student)). However, I have to call class through class_id. Therefore, is there anyway to save the student without get the class object using hibernate?

This is just an example, I have work with a database that a table has many relationship with the others, and it's a pain for me.

Apurv
  • 3,723
  • 3
  • 30
  • 51
Kien Dang Ngoc
  • 1,079
  • 5
  • 15
  • 25

2 Answers2

0

I guess

student.setClass(null);
session.save(student);

should help. Although I am not sure what ". However, I have to call class through class_id" means.

timoras
  • 98
  • 11
0

You may be looking at unidirectional one-to-many relationship(based on class definitions given above) from class to student. You also need to understand cascades. Go through this, and this to learn about associations as you said you have similar scenarios.

Adisesha
  • 5,200
  • 1
  • 32
  • 43