我有以下实体:
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:对象引用了一个未保存的瞬态实例 - 在刷新之前保存瞬态实例: