关于OneToMany中update某一个字段级联操作问题
代码如下:
package com.founder.tweb.entity.cms;import java.util.HashSet;import java.util.List;import java.util.Set;import javax.persistence.CascadeType;import javax.persistence.Entity;import javax.persistence.FetchType;import javax.persistence.GeneratedValue;import javax.persistence.GenerationType;import javax.persistence.Id;import javax.persistence.JoinColumn;import javax.persistence.ManyToOne;import javax.persistence.OneToMany;import javax.persistence.Table;import javax.persistence.Transient;import org.apache.commons.lang.builder.ToStringBuilder;import org.hibernate.annotations.Cache;import org.hibernate.annotations.CacheConcurrencyStrategy;@Entity//表名与类名不相同时重新定义表名.@Table(name = "GROUPLIB")//默认的缓存策略.@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)public class GroupLib {private Integer groupId;private String groupName;private String groupDesc;private String groupType;private Integer groupOrder;private Integer activityId;private Set<MediaGroup> mediaGroups = new HashSet<MediaGroup>();private Set<ImageGroup> imageGroups = new HashSet<ImageGroup>(); //默认构造函数public GroupLib() {}//带参数的构造函数public GroupLib(Integer groupId, String groupName, String groupDesc,String groupType, Integer groupOrder, Integer activityId) {super();this.groupId = groupId;this.groupName = groupName;this.groupDesc = groupDesc;this.groupType = groupType;this.groupOrder = groupOrder;this.activityId = activityId;}@Id@GeneratedValue(strategy = GenerationType.IDENTITY)public Integer getGroupId() {return groupId;}public void setGroupId(Integer groupId) {this.groupId = groupId;}public String getGroupName() {return groupName;}public void setGroupName(String groupName) {this.groupName = groupName;}public String getGroupDesc() {return groupDesc;}public void setGroupDesc(String groupDesc) {this.groupDesc = groupDesc;}public String getGroupType() {return groupType;}public void setGroupType(String groupType) {this.groupType = groupType;}public Integer getGroupOrder() {return groupOrder;}public void setGroupOrder(Integer groupOrder) {this.groupOrder = groupOrder;}public Integer getActivityId() {return activityId;}public void setActivityId(Integer activityId) {this.activityId = activityId;}@OneToMany@JoinColumn(name = "groupId",updatable=false)public Set<MediaGroup> getMediaGroups() {return mediaGroups;}public void setMediaGroups(Set<MediaGroup> mediaGroups) {this.mediaGroups = mediaGroups;}@OneToMany@JoinColumn(name = "groupId",updatable=false)public Set<ImageGroup> getImageGroups() {return imageGroups;}public void setImageGroups(Set<ImageGroup> imageGroups) {this.imageGroups = imageGroups;}@Overridepublic String toString() {return ToStringBuilder.reflectionToString(this);}}? 我的问题是当对表grouplib进行更新操作的时候,对应的mediaGroup中groupId就变成了null,我想改变这种影响,无论是否更新都不会影响mediagroup表,注意红色字体部分中的updatable=false,起了很关键的作用。