我有两个实体曾经通过一对多关系链接,但现在它们通过声明如下的多对多关系链接:
SalesTeam实体:
@Entity
@Table(name = "SALES_TEAMS")
public class SalesTeam {
@Id
@Column(name = "ID")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToMany(fetch = FetchType.LAZY, cascade = {CascadeType.REFRESH, CascadeType.PERSIST})
@JoinTable(name = "WORKFLOW_FOR_SALESTEAM", inverseJoinColumns = {
@JoinColumn(name = "WFC_ID")
})
private List<WorkFlowCode> workFlowCodes = new ArrayList<>();
}
WorkFlowCode实体:
@Entity
@Table(name = "WORK_FLOW_CODE")
public class WorkFlowCode {
@Id
@Column(name = "ID")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToMany(fetch = FetchType.LAZY, cascade = {CascadeType.REFRESH, CascadeType.PERSIST})
@JoinTable(name = "WORKFLOW_FOR_SALESTEAM", inverseJoinColumns = {
@JoinColumn(name = "ST_ID")
})
private List<SalesTeam> salesteam = new ArrayList<>();
}
正如我所说,关系用作几个工作流代码的一个SalesTeam,但需求发生变化,现在它需要是多对多的关系。所以我有一个关系表,并从WORK_FLOW_CODE表中删除以前的SALES_TEAM_ID列。问题是,当我尝试从SalesTeam获取WorkFlowCode时,我总是遇到错误。似乎hibernate仍然将删除的列添加到查询中,因此关系已经改变,并且前一个关系描述中没有任何内容。
这是hibernate生成的查询:
选择workflowco0_.SALES_TEAMS_ID作为SALES_TE3_13_0_,workflowco0_.WFC_ID作为WFC_ID4_16_0_,workflowco1_.ID作为ID1_17_1_来自WORKFLOW_FOR_SALESTEAM workflowco0_ inner join WORK_FLOW_CODE workflowco1_ on workflowco0_.WFC_ID = workflowco1_.ID其中workflowco0_.SALES_TEAMS_ID =?
正如您所见,WORK_FLOW_CODE表中的前SALES_TEAM_ID仍然存在。
如何删除它? THX