java处理hibernate一对多双向关系
我的遗留应用程序中有两个表
Host
和Tables
。表Host
与Tables
具有外键关系(Tables_fk) column
。在我的代码中,我有一个如下的方法
public class Tables {
public void addHosts(Host host) {
getHostsCollection().add(host);
}
}
现在我正在拆分我的数据库,Tables
将进入一个单独的数据库。我现在从Host
中删除Tables_fk
列,并在那里添加一个Table_ID
列,我将从我的应用程序中编写该列。现在,因为我正在从应用程序将Table_ID
写入主机表,所以我猜addHosts(Host host)
方法现在不需要存在
我说得对吗?另外,由于Tables
表与Host
没有任何外键关系,Hibernate在该方法中添加了什么
# 1 楼答案
首先,如果在数据库中删除一个表,hibernate将不再适用于多通关系(表实体),因此:
如果您这样做,您的关系不再是双向的,这种关系将变成单向的,并且工作正常,您仍然可以获取所有的“表”列行