Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JPA需要在CascadeType.refresh的独立实体上显式.refresh吗?_Jpa_Entity_Refresh_Cascade - Fatal编程技术网

JPA需要在CascadeType.refresh的独立实体上显式.refresh吗?

JPA需要在CascadeType.refresh的独立实体上显式.refresh吗?,jpa,entity,refresh,cascade,Jpa,Entity,Refresh,Cascade,为什么我的CascadeType.REFRESH实际上没有刷新我的实体?添加对象时,它不会更新集合(仍然为空) 我需要显式调用entity.refresh()!这是我的部分代码(其中.ALL可以替换为.REFRESH、.PERSIST): @实体 公共类事件扩展模型{ @OneToMany(mappedBy=“event”,cascade=CascadeType.ALL) 公开名单邀请; } @实体 公共类邀请扩展模型 { @多通(级联=级联类型.ALL) 公共事件; } // .. 事件=新事

为什么我的CascadeType.REFRESH实际上没有刷新我的实体?添加对象时,它不会更新集合(仍然为空)

我需要显式调用entity.refresh()!这是我的部分代码(其中.ALL可以替换为.REFRESH、.PERSIST):

@实体
公共类事件扩展模型{
@OneToMany(mappedBy=“event”,cascade=CascadeType.ALL)
公开名单邀请;
}
@实体
公共类邀请扩展模型
{
@多通(级联=级联类型.ALL)
公共事件;
}
// ..
事件=新事件(/*…*/);
event.save();
如果(邀请ID>0)
{
Logger.info(“添加到活动中的邀请”);
Invitation Invitation=Invitation.findById(invitationid);
invite.event=事件;
invite.save();
}
//显式调用它实际上会刷新对象并显示邀请。
//event.refresh();
if(event.investments==null | | event.investments.size()==0)
Logger.info(“仍然为空?!”);
// ..
我在玩!hibernate-jpa-2.0附带的框架。

您负责对象图的一致性。当您保存一个子项时,JPA不会自动将该子项添加到父项集合中。因此,这是你的责任

Invitation invitation = new Invitation();
invitation.setEvent(event);
event.getInvitations().add(invitation);
最好将其封装在
事件
类的
附加激励
方法中:

public void addInvitation(invitation) {
    this.invitations.add(invitation);
    invitation.setEvent(this);
}
public void addInvitation(invitation) {
    this.invitations.add(invitation);
    invitation.setEvent(this);
}