Play 2.0.Xでは、このように1対多の関係が作成されます。親から子メンバーを削除する正しい方法は何ですか。iter.remove()またはchild.delete()を使用する必要がありますか?
@Entity
@Table(name="channel")
public class ChannelInfo extends Model {
@Id
private Long id;
@Constraints.Required
private String channelName;
@OneToMany(cascade=CascadeType.ALL, mappedBy="channelInfo")
private Set<ChannelDetailMember> members;
private int membersCount = 0;
public void removeMemberId(String memberId) {
Iterator<ChannelDetailMember> iter = this.getMembers().iterator();
while (iter.hasNext()) {
ChannelDetailMember dMember = iter.next();
if (dMember.getMemberId().equals(memberId)) {
dMember.delete();
membersCount--;
break;
}
}
}
}
@Entity
@Table(name="channel_detail")
public class ChannelDetailMember extends Model {
@Id
private Long id;
@Constraints.Required
private String memberId;
@Constraints.Required
@ManyToOne(cascade=CascadeType.PERSIST)
ChannelInfo channelInfo;
}