我有以下邀请:
Channel
@ManyToOne(cascade = { CascadeType.ALL })
@JoinColumn(name = "campaign_business_id")
private CampaignBusiness campaignBusiness;
@ManyToOne(cascade = { CascadeType.ALL })
@JoinColumn(name = "campaign_id")
private Campaign campaign;
Campaign
@ManyToOne(cascade = { CascadeType.ALL })
@JoinColumn(name = "event_id")
private Event event;
CampaignBusiness
@ManyToOne
@JoinColumn(name = "campaign_id")
private Campaign campaign;
我只想使用 Cascade.PERSIST - 因为我希望记录更新,而不是在casacde上删除。
但是,当我写而不是 Cascade.ALL , Cascade.PERSIST 时,请使用以下代码:
Event event = new Event();
Campaign campaign = new Campaign();
campaign.setEvent(event);
CampaignBusiness campaignBusiness = new CampaignBusiness();
campaignBusiness.setCampaign(campaign);
Channel channel = new Channel();
channel.setCampaign(campaign);
channel.setCampaignBusiness(campaignBusiness);
channelDAO.save(channel);
我得到了一个例外
org.hibernate.TransientObjectException:object引用未保存的 瞬态实例 - 在刷新之前保存瞬态实例: