2010-11-12 75 views
1

我試圖讓這個映射工作休眠,但我得到這個奇怪的異常消息映射例外與CollectionOfElements

Could not determine type for: foo.ProcessUser, at table: ProcessUser_onetimeCodes, for columns: [org.hibernate.mapping.Column(processUser)]

@Entity 
public class ProcessUser { 

    @Setter 
    private List<OnetimeCodes> onetimeCodes; 

    @CollectionOfElements 
public List<OnetimeCodes> getOnetimeCodes() { 
    return onetimeCodes; 
    } 
} 


@Embeddable 
@Data 
public class OnetimeCodes { 

    @Parent 
    private ProcessUser processUser; 

    @Column(nullable=false) 
    @NotEmpty 
    private String password; 


    public OnetimeCodes(ProcessUser processUser, String password) { 
     this.processUser = processUser; 
     this.password = password; 
    } 
} 

任何人能發現什麼是錯在這裏嗎? 我有hibernate.hbm2ddl.autocreate

回答

2

我發現了錯誤。

您不能在其中一個類中的屬性和另一個類中的getter上進行映射。他們應該匹配。

因此,我改變

@Embeddable 
@Data 
public class OnetimeCodes { 

    @Parent 
    private ProcessUser processUser; 

    @Column(nullable=false) 
    @NotEmpty 
    private String password; 


    public OnetimeCodes(ProcessUser processUser, String password) { 
     this.processUser = processUser; 
     this.password = password; 
    } 
} 

@Embeddable 
public class OnetimeCodes { 

    private ProcessUser processUser; 

    private String password; 

    public OnetimeCodes(ProcessUser processUser, String password) { 
     this.processUser = processUser; 
     this.password = password; 
    } 

    @Parent 
    public ProcessUser getProcessUser() { 
     return processUser; 
    } 

    public void setProcessUser(ProcessUser processUser) { 
     this.processUser = processUser; 
    } 

    @Column(nullable=false) 
    @NotEmpty 
    public String getPassword() { 
     return password; 
    } 

    public void setPassword(String password) { 
     this.password = password; 
    } 
} 

和中提琴。 如果你問我,這很愚蠢。

+0

該框架是愚蠢的。我有同樣的問題。我的設置非常複雜(具有多對一關係的複合外鍵),我從來沒有想到它就是這樣。不僅框架的代碼不好,文檔也是如此,因爲它永遠不會讓'@ EmbeddedId'放在getter上。 – tiktak 2015-01-18 00:29:59