我正在学习hibernate并且开始知道它是一个ORM工具。
@Entity
@Table(name="USER_DETAILS")
public class UserInfo {
@ElementCollection
Set<Address> addressList = new HashSet<Address>();
// Some other code...
}
public class MainApp {
public static void main(String s[]) {
SessionFactory sf = null;
sf = new Configuration().configure().buildSessionFactory(); // This will read the hibernate.cfg.xml file
// We can save using session.save(object)
}
}
从代码中可以看出,addressList
实体中有UserInfo
(集合)。
当我们保存实体时,embedded object
是否会自动保存为实体的一部分,或者我们还需要专门保存collection object
?
答案 0 :(得分:0)