2013-02-13 59 views
1

我有以下簡單的例子:一對多的單向同在許多方面組合大PK

@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; 
} 

每當我試着堅持一個配置文件,有兩個INSERT語句:

插入到檔案( ID)值() - PERFECT

INSERT INTO偏好(簡檔,ID)值(,) - ?也是完美

然後

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

你能發佈PreferenceId類的代碼嗎?也許它與您在實體中用@Id標記的字段不匹配...... – overmeulen 2013-02-15 11:18:47

回答

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 
}