我有以下简单示例:
@Entity
public class Profile {
@Id
private long id;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name="profileId", nullable = false)
private List<Preference> preferences;
}
@Entity
@IdClass(PreferenceId.class)
public class Preference1 {
@Id
private long id;
@Id
@Column(insertable = false, updatable = false, nullable = false)
private long profileId;
}
每当我尝试保留配置文件时,都会有两个插入语句:
插入Profile(id)值(?) - PERFECT
插入Preference(profileId,id)值(?,?) - 同样PERFECT
然后
16:21:12,257 TRACE BasicBinder:83 - binding parameter [1] as [BIGINT] - 1
16:21:12,257 TRACE BasicBinder:83 - binding parameter [2] as [BIGINT] - 10
16:21:12,257 TRACE BasicBinder:83 - binding parameter [3] as [BIGINT] - 0
16:21:12,257 ERROR SqlExceptionHelper:144 - Invalid column index
为什么有三个参数而不是两个?
答案 0 :(得分:0)
public class PreferenceId implements Serializable {
private long id;
private long profileId;
public PreferenceId(){}
public long getId(){return id;}
public void setId(long id){this.id = id;}
public long getProfileId() {return profileId;}
public void setProfileId(long profileId) {this.profileId = profileId;}
//hashCode, equals
}