[英]Saving an object to table that has relationship with another table using hibernate
我有2張桌子。
Student (id,name,class_id)<br>
class(id,name)
student
通過class_id
與class
表class_id
使用休眠並生成對象后,我將有2個對象
Student { int id; String name; Class class }
Class {int id; String name; Set<Student> student}
我想使用休眠( session.save(student)
)保存學生信息。 但是,我必須通過class_id
來調用class。 因此,是否有任何方法可以在不使用休眠狀態獲取類對象的情況下保存學生?
這只是一個例子,我正在使用一個數據庫,其中一個表與其他表有很多關系,這對我來說很痛苦。
我猜
student.setClass(null);
session.save(student);
應該有所幫助。 雖然我不確定“。但是,我必須通過class_id來調用class”的意思。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.